Skip to content
Advertisement

Bash-script to toggle espeak by keyboard shortcut

To read a selected text in GUI out loud I use the command xsel | espeak-ng -v mb-us3 -p3 -s135. To stop it I use killall -s STOP espeak-ng. To start it again killall -s CONT espeak-ng.

All 3 commands work, but the noob I am won’t let me archive correct results. The problem is in the if- and case-statement I think. I assigned them to a keyboard shortcut.

I want to manage this shellscript to toggle between read aloud and stopping the process of reading aloud if espeak-ng is already running. If it’s not already running the bash should start it.

JavaScript

I don’t even know how to test the output of: if [[ $(pgrep -x espeak-ng) ]]

Can somebody help me to figure out what’s wrong and give me some hints? Many thanks in advance.

Advertisement

Answer

after struggling a bit by myself I found out that there is a difference between ps -ef and ps ax in the order of printing out some values…

Also I have to admit that the end of line 10 looks awful. It has to be ...print $5}'` . Because of the difference between ps -ef and ps ax of course it has to be ...print $3}'` .

By the way. The dependencies are xsel and espeak-ng and at least one mbrola-voice.

Now it works. Here is the full code:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement