Text to speech in (neo)vim...
Some dirty hacks to read the vim buffer with espeak.
|
|
What does the command mean
A simplified version is:
:.,$w !espeak
:go to command mode.,$is a range filter,.means the current line,$means end of file.wmeans write, but unlike your normal:wq, it doesn’t write to a file. Instead the text is written to the stdio of a command started by a bang!espeakthis is the final (external) command.setsid -fsee below.
What is setsid -f
- It’s simple, you don’t want to block your editor while playing the sound! So you want espeak to run “in the background”.
- I’m being lazy here, setsid -f is to tell the shell to always create new process (fork)
- Another option is to use nohup and redirect output to /dev/null
- There are better ways to do it, see below
Actung dirty Hack!
- Perhaps I should use async instead of
setsid -f, and keep espeak as a daemon. - Perhaps I should make the parameters configurable, but since I’m not publishing a plugin, this should be fine… daemon.
Conclusion: it works.