ideasman42 / nerd-dictation

Simple, hackable offline speech to text - using the VOSK-API.
GNU General Public License v3.0
1.3k stars 107 forks source link

How to capitalize every sentence #59

Open ChristianNext opened 2 years ago

ChristianNext commented 2 years ago

--full-sentence --punctuate-from-previous-timeout 2

This only capitalizes the first sentence, but not subsequent, plse advise.

NathanLovato commented 2 years ago

In your configuration file, add something like this. It capitalizes the first letter after a period, exclamation mark, or question mark.

import re

def nerd_dictation_process(text):
    #...
    # Add sentence case
    REGEX_SENTENCE = re.compile(r"[\.?!] [a-z]")
    def apply_sentence_case(match):
        return match.group(0).upper()
    text = REGEX_SENTENCE.sub(apply_sentence_case, text)
    #...
    return text
ChristianNext commented 2 years ago

Works brilliantly, many tks! nerd-dictation is a great time saver for me and works like a charm, fantastic work.

Capitalizing sentence beginning might be a common request. I suggest it be added as a command-line option or to nerd_dictation_process.py

Lume6 commented 2 years ago

Hi ! Thank you for your contribution. Could you tell me exactly where I should copy your text? It may seem strange but I get an error message. Failed to run "/home/bernard/.config/nerd-dictation/nerd-dictation.py" with error: unexpected indent (nerd-dictation.py, line 159) This corresponds to return text

As I understood it, I inserted it after :

# Main Processing Function

def nerd_dictation_process(text):

    for match, replacement in TEXT_REPLACE_REGEX:
        text = match.sub(replacement, text)

  words[i] = w

# Add sentence case
  REGEX_SENTENCE = re.compile(r"[\.?!] [a-z]")
    def apply_sentence_case(match):
        return match.group(0).upper()
    text = REGEX_SENTENCE.sub(apply_sentence_case, text)
           return text 

I think there is an error somewhere! Can you tell me where to put return text ? Thank you.

Translated with www.DeepL.com/Translator (free version)

joelostblom commented 1 year ago

A note that the workaround only seems to work if you are inserting the punctuation via voice typing rather than using the keyboard for punctuation together with the voice for the text since it is not the actual text in the input box that is analyzed, just the text that is spoken. So you would need to use this in combnation with osmething like https://github.com/ideasman42/nerd-dictation/blob/main/examples/default/nerd-dictation.py

nshmyrev commented 1 year ago

We can release small and fast (50mb) autopunctuation/capitalization model soon btw.

joelostblom commented 1 year ago

Wow, that is great! Looking forward to that being available!