有没有办法从命令行使用 MS Speech 实用程序?我可以在 Mac 上完成,但在 Windows XP 上找不到任何引用。
7 回答
我在这个主题上的 2 美分,命令行单行:
在 Win 上使用
PowerShell.exe
PowerShell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('hello');"
在 Win 上使用
mshta.exe
mshta vbscript:Execute("CreateObject(""SAPI.SpVoice"").Speak(""Hello"")(window.close)")
在 OSX 上使用
say
say "hello"
使用本机的 Ubuntu 桌面 (>=2015)
spd-say
spd-say "hello"
在任何其他 Linux 上
- 请参阅如何使用命令行将文本转语音输出?
- 使用 google TTS的命令行功能(wget 到 mp3->mplayer)
- 直接使用 google和 mplayer命令:
/usr/bin/mplayer -ao alsa -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=Hello%20World&tl=en"
;
在 Raspberry Pi、Win、OSX(或任何远程)上使用Node-Red
有一个很好的开源程序可以在 Windows 上执行您所要求的操作,称为 Peter's Text to Speech,可在此处获得:http: //jampal.sourceforge.net/ptts.html
它包含一个名为 ptts.exe 的二进制文件,它将从标准输入中读出文本,因此您可以像这样运行它:
echo hello there | ptts.exe
或者,您可以使用以下三行 VBS 脚本来获得类似的基本 TTS:
'say.vbs
set s = CreateObject("SAPI.SpVoice")
s.Speak Wscript.Arguments(0), 3
s.WaitUntilDone(1000)
你可以像这样从命令行调用它:
cscript say.vbs "hello there"
如果您使用脚本路线,您可能希望找到一些更广泛的代码示例,其中包含可变超时和错误处理。
希望能帮助到你。
如果找不到命令,您始终可以从 .Net 3.0 包装System.Speech.Synthesis.SpeechSynthesizer(不要忘记引用“System.Speech”)
using System.Speech.Synthesis;
namespace Talk
{
class Program
{
static void Main(string[] args)
{
using (var ss = new SpeechSynthesizer())
foreach (var toSay in args)
ss.Speak(toSay);
}
}
}
还有一种powershell方式:
创建一个名为 speak.ps1 的文件
param([string]$inputText)
Add-Type –AssemblyName System.Speech
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$synth.Speak($inputText);
然后你可以调用它
.\speak.ps1 "I'm sorry Dave, I'm afraid I can't do that"
还有Balabolca:http ://www.cross-plus-a.com/bconsole.htm
它有一个命令行工具balcon.exe
。你可以像这样使用它:
列出声音:
balcon.exe -l
发言文件:
balcon.exe -n "IVONA 2 Jennifer" -f file.txt
从命令行说话:
balcon.exe -n "IVONA 2 Jennifer" -t "hello there"
更多命令行选项可用。我在 Ubuntu 上尝试了它,并在 Wine 中安装了 SAPI5。它工作得很好。
rem The user decides what to convert here
:input
cls
echo Type in what you want the computer to say and then press the enter key.
echo.
set /p text=
rem Making the temp file
:num
set num=%random%
if exist temp%num%.vbs goto num
echo ' > "temp%num%.vbs"
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp%num%.vbs"
echo speech.speak "%text%" >> "temp%num%.vbs"
start temp%num%.vbs
pause
del temp%num%.vbs
goto input
pause
您最好的方法是编写一个小型命令行实用程序来为您执行此操作。这不会是很多工作 - 只需阅读文本然后使用 ms tts 库。
另一种选择是使用倒谱。它带有一个不错的命令行实用程序,听起来比 ms tts 好几年。