K
Krazy Glew
BRIEF: When speech recognition software occasionally inserts extra blank spaces at the beginning of lines that are being dictated into emacs fundamental or textmode, how can the bad stuff below be avoided in the 1st place, or fixed up most conveniently?
Specifically Dragon speech recognition from Nuance (now owned by Microsoft).
Dragon typically inserts one blank space between words, and 1 or 2 blank spaces before the next word after the end of the sentence, if Dragon thinks appropriate. E.g. if Dragon thinks you are in the same flow of text, not at the beginning of a paragraph or after a hard newline. This works for "speech-ready" applications that allow Dragon to determine the state or context of the dictation.
Unfortunately, EMACS is not speech aware. Dragon will infer that it is at the beginning of a line if Dragon has seen the user dictate "newline" or some other line ending utterance. But Dragon's notion of state or context will fall out of sync (a) if the user types a key, rather than going through Dragon, or (b) if the user executes an emacs command like goto-line or kill-line that Dragon, and (c) in similar circumstances.
These extra spaces cause problems. (As similarly does Dragon's inferred capitalization of words, but that's not part of this question.)
This question seeks advice on how best to mitigate one particularly annoying aspect of this problem: when these extra spaces are inserted at the beginning of a line of text.
Below I provide a probably too large example of some of the artifacts that occur when dictating into EMACS fundamental mode or text mode. Both in my default setup, but also with all emacs startup files disabled. With electric-indent-mode both on and off.
The example is probably too large, and I may reduce its size in subsequent updates of this question. I'm somewhat reluctant to actually edit the example - I would prefer to have the example be exactly what I dictated - but that's a bit hard to make concise.
The short version is:
In the default configuration, with electric-indent-mode on, dictating text text, While also dictating new lines, mostly looks OK
I am sure there are other, better, ways to prevent this problem from happening and/or repair it once it has happened.
I've already tried some things, and considered other approaches. I will post some of these as pseudo-answers, but I will not do so immediately.
Posting to https://emacs.stackexchange.com because the answer is almost certainly to write elisp code, since emacs is much more flexible than Dragon. some of the approaches that I have considered are purely elisp based, but some are a hybrid of elisp code and Dragon configurations, possibly Dragon extensions or plug-ins.
This is one of the of what will be several questions related to making emacs friendlier to speech recognition and voice control software. In particular Dragon speech recognition software from Nuance (now owned by Microsoft), because that is what I'm currently using, but I'm open to other speech recognition and voice control software packages.
Code:
blah blah blah
blah blah blah
blah blah blah
---+ DETAIL
I use speech recognition to dictate text into EMACS; also to invoke emacs commands, sometimes directly, but usually from "speech commands" in the speech software package.Specifically Dragon speech recognition from Nuance (now owned by Microsoft).
Dragon typically inserts one blank space between words, and 1 or 2 blank spaces before the next word after the end of the sentence, if Dragon thinks appropriate. E.g. if Dragon thinks you are in the same flow of text, not at the beginning of a paragraph or after a hard newline. This works for "speech-ready" applications that allow Dragon to determine the state or context of the dictation.
Unfortunately, EMACS is not speech aware. Dragon will infer that it is at the beginning of a line if Dragon has seen the user dictate "newline" or some other line ending utterance. But Dragon's notion of state or context will fall out of sync (a) if the user types a key, rather than going through Dragon, or (b) if the user executes an emacs command like goto-line or kill-line that Dragon, and (c) in similar circumstances.
These extra spaces cause problems. (As similarly does Dragon's inferred capitalization of words, but that's not part of this question.)
This question seeks advice on how best to mitigate one particularly annoying aspect of this problem: when these extra spaces are inserted at the beginning of a line of text.
Below I provide a probably too large example of some of the artifacts that occur when dictating into EMACS fundamental mode or text mode. Both in my default setup, but also with all emacs startup files disabled. With electric-indent-mode both on and off.
The example is probably too large, and I may reduce its size in subsequent updates of this question. I'm somewhat reluctant to actually edit the example - I would prefer to have the example be exactly what I dictated - but that's a bit hard to make concise.
The short version is:
In the default configuration, with electric-indent-mode on, dictating text text, While also dictating new lines, mostly looks OK
Code:
this text is dictated, and Dragon sees the command that ends this line
this is the new line
and this is another line, again with Dragon seeing the end of line
but here the previous line was terminated by physically pressing Enter
here as well
and so on
because with electric-indent-mode on,
each new line is aligned to the previous
And then the extra space indents further.
the above had electric-indent-mode on.
with electric indent mode off
we don't get this incrementing alignment behavior
but we do get extra whitespace at the beginning of the line
if Dragon is not aware of the end of line.
- It's not that hard to fix, e.g. by pressing TAB to invoke indent-for-tab-command, which typically invokes indent-relative.
- although that does not remove the extra space of indentation that might've been inserted at the very 1st line.
- I am a bit embarrassed to admit that I frequently resort to indent-rigidly
- but I'm even more embarrassed to admit that quite a few of my git commit messages in my private repo exhibit such damage - especially when I had just started using Dragon and emacs.
I am sure there are other, better, ways to prevent this problem from happening and/or repair it once it has happened.
There are probably some standard ways to repair this damage that I don't know about: settings and/or commands that are especially convenient.
- I look forward to answers that tell me that I am an idiot for not knowing about them.
I suspect that avoiding this damage requires that new code be written.
- Although perhaps somebody has already solved this problem
And I seek advice as to the best ways to approach coding was to avoid this problem in the 1st place, or at least where it gets too bad.
I've already tried some things, and considered other approaches. I will post some of these as pseudo-answers, but I will not do so immediately.
Posting to https://emacs.stackexchange.com because the answer is almost certainly to write elisp code, since emacs is much more flexible than Dragon. some of the approaches that I have considered are purely elisp based, but some are a hybrid of elisp code and Dragon configurations, possibly Dragon extensions or plug-ins.
This is one of the of what will be several questions related to making emacs friendlier to speech recognition and voice control software. In particular Dragon speech recognition software from Nuance (now owned by Microsoft), because that is what I'm currently using, but I'm open to other speech recognition and voice control software packages.
---+ BIG EXAMPLE
Code:
blah blah blah
blah blah blah
blah blah blah
---+ PROBLEM: incrementally incrementing indentation
frequently text files that I have dictated into using Dragon speech recognition
look like this, with successive lines frequently having one extra blank on the left
being progressively more indented
because Dragon has not seen me physically pressing the enter key
so Dragon thinks I'm still dictating on the same line or in the same paragraph
however if I say "newline" or "press enter" on the end of the line
no problem occurs, because then Dragon has seen the actual transition
the extra indentation occurs because I frequently hit enter on the keyboard,
forgetting to say "newline" or "press enter" to Dragon
it also happens when I
go back to a line
i.e. when I'm editing nonlinearly
I have emacs set to delete white space at the end of lines
so if I move to a blank line
pres TAB to align
I still get an extra blank.
---+ BACKGROUND
I use speech recognition because it hurts me to type too much.
But I can still type, and I often use a "hybrid mode" where I dictate most
but where I will press a small number of physical keys
typically large easy to find keys like and enter
and I will usually use a trackball
rather than using the IMHO very annoying ways of moving the mouse by voice.
at 1st I thought I was being "impure" by using such a hybrid mode
for speech control, but it turns out a lot of people do this
if they can.
Observation:
+ speech recognition is pretty efficient for dictating text.
+ Also for invoking "speech commands"
+ including emacs commands by voice
+ far fewer problems avoiding key-binding conflicts
+ but speech recognition is somewhat inefficient for simple keypresses
+ compare saying "press enter" to simply hitting a large enter key
Yes: I know about things
+ demos of emacs by voice such as
+ https://whalequench.club/blog/2019/09/14/strange-loop.html
+ Tavis Rudd's famous "coding by voice... using a combination of grunts and animal sounds"
+ I also know about things like
+ talon
+ DragonFly
"Know of", I've chosen to go a slightly different direction.
this is not the place to discuss overall approacesh to voice control.
I just want to talk about this 1 specific problem that arises when I
use Dragon to dictate into emacs fundamental mode.
blah blah blah
blah blah blah
if I keyboard 2 blank lines, I return to the right
emacs help tells me that the key-binding "RET (translated from <return>) runs the command newline"
if I say
or press
TAB
on such an indented line
it gets fixed (which I'll go back and demonstrate)
because
"TAB (translated from <tab>) runs the command indent-according-to-mode"
I forget
if I have
auto indent on
indeed it looks like I do
---+ no startup files
OK, I just started emacs --no-init-file --no-site-file
to get an absolutely fresh set up
but see what happens now
Yep I still get the extra indentation
if I start new from the keyboard
what happens if I do goto-line in emacs (target this line)
Yep I get the indentation
The above is with electric-indent-mode t, i.e. on, the default in recent emacs
---+ disabling electric-indent-mode
Now I have disabled electric indent mode.
no extra space when Dragon saw the new line
this is what I get when actually press the physical key enter
but of course I don't get the incrementing behavior
I just get one extra space at the beginning line.
But that one extra space can cause problems e.g. in some markup languages.
---+ org-mode
now I have switched to Org mode
+ 1st list item
+ 2nd list item
+ again, if I hit the enter key
but it is not just hitting the enter key.
+ Dragon also does not see the state of the buffer when I have
executed an Emacs command, whether invoked from the keyboard or from
the voice command,
+ e.g. goto-line
+ e.g. killing a line and then typing new contents