要大声读取GUI中的选定文本,请使用命令xsel | espeak-ng -v mb-us3 -p3 -s135
。
要停止它,我使用killall -s STOP espeak-ng
。
要重新开始killall -s CONT espeak-ng
。
所有3个命令都可以使用,但是我的菜鸟不会让我存档正确的结果。问题在于我认为的if和case陈述。我将它们分配给键盘快捷键。
如果espeak-ng已经在运行,我想管理此shellscript在大声朗读和停止大声朗读的过程之间切换。如果尚未运行bash,则应启动它。
0 #!/bin/bash
1 # Name: espeak-en.sh
2 # Author: Karsten Zarth
3 # Created: 2020-08-23
4 # Description: Textselection in GUI is read aloud with english
5 # male voice with espeak-ng and mbrula
6 # if already reading: stop
7 # if stopped: continue
8 # Modified: 2020-08-23
9
10 status=`ps -ef| grep espeak-ng| grep -v grep| awk '{print $5}"`
11
12 if [[ $(pgrep -x espeak-ng) ]]
13 then
14 case $status in
15 Tl) killall -s CONT espeak-ng;;
16 Sl) killall -s STOP espeak-ng;;
17 esac
18 else
19 xsel | espeak-ng -v mb-us3 -p3 -s135
20 fi
我什至都不知道如何测试if [[ $(pgrep -x espeak-ng) ]]
有人可以帮助我找出问题所在并给我一些提示吗?预先非常感谢。
答案 0 :(得分:0)
我自己苦苦挣扎之后,发现ps -ef
和ps ax
之间的区别在于打印一些值的顺序...
我还必须承认第10行的结尾看起来很糟糕。它必须是...print $5}'`
。由于ps -ef
和ps ax
之间的差异,当然必须为...print $3}'`
。
顺便说一句。依存关系为xsel
和espeak-ng
以及至少一个mbrola-voice。
现在可以使用了。这是完整的代码:
0 #!/bin/bash
1 # Name: espeak-en.sh
2 # Author: Karsten Zarth
3 # Created: 2020-08-23
4 # Description: Textselection in GUI is read aloud with english
5 # male voice with espeak-ng and mbrula
6 # if already reading: stop
7 # if stopped: continue
8 # Modified: 2020-08-24
9
10 status=`ps ax| grep espeak-ng| grep -v grep| awk '{print $3}'`
11
12 if [[ $(pgrep -x espeak-ng) ]]
13 then
14 case $status in
15 Tl) killall -s CONT espeak-ng;;
16 Sl) killall -s STOP espeak-ng;;
17 esac
18 else
19 xsel | espeak-ng -v mb-us3 -p3 -s135
20 fi