Open landemou opened 2 years ago
Hi landemou,
I just started using nerd-dictation myself. I created a substitution based config (within ~/.config/nerd-dictation/nerd-dictation.py
) for punctuation etc. that does some stuff similar to what I think you're trying to do. Is it likely the most elegant approach? No, but it works well enough for me :)
# A list of substitutions to make within the dictated text
substitutions = [('period', '.'),
('comma', ','),
('new line', '\r'),
('dash', '-'),
('back slash', '\\'),
('forward slash', '/'),
('question mark', '?'),
('exclamation mark', '!'),
('ampersand', '&'),
('asterisk', '*')
]
def nerd_dictation_process(text):
# Substitute in alternate text for any entries within substitutions list
for substitution in substitutions:
text = text.replace(' ' + substitution[0], substitution[1])
text = text.replace(substitution[0], substitution[1])
# Fix any new lines with a trailing space
text = text.replace('\r ', '\r')
return text
I do each replacement twice, first with a space beforehand, then without a space before. This should cover both normal punctuation inserted after the start of a sentence, removing the space in between the text and punctuation mark, and cases where you want punctuation at the start of your dictation. Note I also have a 'new line' entry, that inserts the carriage return character. I also replace '\r ' with '\r' to remove the space that would otherwise be added to the start of a new line.
Of course, depending on your use case, you may need to have your code actually simulate pressing the enter key, instead of just inserting a '\r', but hope this at least gives some inspiration :)
Thanks a lot for your help CB9001 Great job !
Worth noting there is also a more in-depth example with punctuation and some other substitutions @ https://github.com/ideasman42/nerd-dictation/blob/master/examples/default/nerd-dictation.py
Is there any reason to keep this issue open?
Thanks a lot for your help CB9001 Great job !
Hi Landemou,
I'm French too. Could you tell me if you succeed by using the punctuation ? For instance, ! ? ; : which are not recognized .
For example :
Il fait froid. d'interrogation. Il fait froid.s de suspension
, etc.
In the nerd-dictation.py file :
`# Add Punctuation CLOSING_PUNCTUATION = {
"point": ".", "virgule": ",", "point d'interrogation": "?", "fermer les guillemets": '"', "point d'exclamation": "!", "points de suspension": "...", "point virgule": ";",
Don't don't hesitate to write me if you think it's easier.
Thanks. `
Hi Lume6,
I'm currently on other projects but I'm keeping an eye on this one. I advise you to look at this example (nerd-dictation/examples/default/nerd-dictation.py). Your multi-word commands are visibly interpreted from the first word.
For what does not work with your code you can try :
TEXT_REPLACE_REGEX = ( ("\\b" "point d'interrogation" "\\b", "?"), ("\\b" "point d'exclamation" "\\b", "!"), )
If you manage to do (point à la ligne et saut de ligne) i'm interested ! You can contact me : landemou@hotmail.com
Good luck 👍
If you manage to do (point à la ligne et saut de ligne) i'm interested !
@landemou
it looks like WORD_REPLACE parts in ~/.config/nerd-dictation/nerd-dictation.py
is not working very accurately. Their
"linux": "Linux",
is working, but not further words I've added.
Anyway, to do a point à la ligne, I've included it into CLOSING_PUNCTUATION:
CLOSING_PUNCTUATION = {
"trois petits points": "… ",
"deux points": " : ",
"point de suspension": "… ",
"point d'interrogation": " ? ",
"point d'exclamation": " ! ",
"point": ". ",
"virgule": ", ",
"fermez les guillemets": ' » ',
"retour à la ligne": "\r",
I've tried with \n
and it didn't work, but \r
does
First of all thank you for this very useful project. I need to incorporate punctuation into dictation (in french). Replace single and multiple words works very well. But I encounter a difficulty with the need to be able to make a point and then return to the line. I am beginner in python ...
The best I've managed to do looks like this : if text == "point à la ligne": text = "." run_xdotool("key", ["Return"])
And by the way make sure that there is no space before the point. I searched for a while but here I am stuck, thanks in advance.