我正在尝试定义一个一行别名,如下所示:
alias speak='curl -G --data-urlencode "text=$(cat /dev/stdin)" "https://speech.botiumbox.com/api/tts/en?&tts=marytts" -H "accept: audio/wav" | mpv -'这样我就可以像这样使用它
echo Hello World! | speak
speak Hello World!
speak<RET> # continuously do TTS per line until ^D
Hello World!
Another line!
<Ctrl-D>如果我使用
curl -G --data-urlencode "text=Hello World!" "https://speech.botiumbox.com/api/tts/en?&tts=marytts" -H "accept: audio/wav" | mpv -如上所述,简单地采用cat /dev/stdin的标准输入似乎并不能创建交互式的命令行界面程序。有什么想法可以把这个API封装到一个交互式的CLI程序中吗?理想情况下,应该与POSIX兼容,这样它就可以在Unixen中的bash shell中运行。
发布于 2020-06-12 05:57:59
我发现了一个使用bash函数而不是别名的变通方法。函数marySpeak接受一个字符串,将其在线发送给TTS,然后使用mpv回放它。一切都被定义为一行,所以可以放在你的.bashrc中
marySpeak() { curl -s -G --data-urlencode "text=$1" "https://speech.botiumbox.com/api/tts/en?&tts=marytts" -H "accept: audio/wav" | mpv - 2>&1 > /dev/null; }
# then simply use it like this
marySpeak "hello world!"在GNU/Linux和macOS上进行了测试。
https://stackoverflow.com/questions/62202632
复制相似问题