【发布时间】:2010-11-05 15:42:28
【问题描述】:
有没有办法从命令行使用 MS Speech 实用程序?我可以在 mac 上完成,但在 Windows XP 上找不到任何参考。
【问题讨论】:
标签: cmd text-to-speech
有没有办法从命令行使用 MS Speech 实用程序?我可以在 mac 上完成,但在 Windows XP 上找不到任何参考。
【问题讨论】:
标签: cmd text-to-speech
我在主题上的 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 上
/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
npm i @987654324@
【讨论】:
有一个很好的开源程序可以在 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"
如果您使用脚本路线,您可能希望找到一些更广泛的代码示例,其中包含可变超时和错误处理。
希望对你有帮助。
【讨论】:
C:\Program Files\Jampal>cscript "c:\program files\jampal\ptts.vbs" -voice "IVONA Amy" < raven.txt 和 C:\Program Files\Jampal>cscript "c:\program files\jampal\ptts.vbs" -voice "IVONA Jennifer" < raven.txt
如果找不到命令,您可以随时将 .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 库。
另一种选择是使用Cepstral。它带有一个不错的命令行实用程序,听起来比 ms tts 好几年。
【讨论】: