38

有没有办法从命令行使用 MS Speech 实用程序?我可以在 Mac 上完成,但在 Windows XP 上找不到任何引用。

4

7 回答 7

59

我在这个主题上的 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 上

  • 在 Raspberry Pi、Win、OSX(或任何远程)上使用Node-Red

    npm i node-red-contrib-sysmessage

于 2016-09-22T19:51:26.197 回答
25

有一个很好的开源程序可以在 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"

如果您使用脚本路线,您可能希望找到一些更广泛的代码示例,其中包含可变超时和错误处理。

希望能帮助到你。

于 2009-06-24T20:35:06.187 回答
4

如果找不到命令,您始终可以从 .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);
        }
    }
}
于 2009-06-24T20:17:40.917 回答
4

还有一种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"
于 2016-04-09T20:41:46.123 回答
4

还有Balabolcahttp ://www.cross-plus-a.com/bconsole.htm 它有一个命令行工具balcon.exe。你可以像这样使用它:

  1. 列出声音:

    balcon.exe -l
    
  2. 发言文件:

    balcon.exe -n "IVONA 2 Jennifer" -f file.txt
    
  3. 从命令行说话:

    balcon.exe -n "IVONA 2 Jennifer" -t "hello there"
    

更多命令行选项可用。我在 Ubuntu 上尝试了它,并在 Wine 中安装了 SAPI5。它工作得很好。

于 2017-08-08T13:35:07.903 回答
3
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
于 2014-02-03T15:31:42.723 回答
2

您最好的方法是编写一个小型命令行实用程序来为您执行此操作。这不会是很多工作 - 只需阅读文本然后使用 ms tts 库。

另一种选择是使用倒谱。它带有一个不错的命令行实用程序,听起来比 ms tts 好几年。

于 2009-06-24T20:19:17.873 回答