来自命令行的 ms 语音

发布于 2024-07-25 04:54:24 字数 75 浏览 9 评论 0原文

有没有办法从命令行使用 MS Speech 实用程序? 我可以在 Mac 上执行此操作,但在 Windows XP 上找不到任何参考。

Is there a way to use the MS Speech utility from command line? I can do it on a mac, but can't find any reference to it on Windows XP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

也只是曾经 2024-08-01 04:54:24

我对这个主题的 2 美分,命令行一句:

  • 在 Win8+ 上 (WinXP) 使用 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

     说“你好” 
      
  • Ubuntu Desktop (>=2015) 使用本机 spd-say

     spd-say“你好” 
      
  • 在任何其他 Linux 上使用本机 spd-say

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

    npm 我 node-red-contrib-sysmessage

My 2 cents on the topic, command line one-liners:

  • on Win8+ (WinXP) using PowerShell.exe

      PowerShell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('hello');"
    
  • on Win using mshta.exe (might not be available in corp. env.)

      mshta vbscript:Execute("CreateObject(""SAPI.SpVoice"").Speak(""Hello"")(window.close)")
    
  • on OSX using say

      say "hello"
    
  • Ubuntu Desktop (>=2015) using native spd-say

      spd-say "hello"
    
  • on any other Linux

  • on Raspberry Pi, Win, OSX (or any remote) using Node-Red

    npm i node-red-contrib-sysmessage

爱格式化 2024-08-01 04:54:24

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

如果您采用脚本路线,您可能会希望找到一些具有可变超时和错误处理的更广泛的代码示例。

希望能帮助到你。

There's a nice open source program that does what you're asking for on Windows called Peter's Text to Speech available here: http://jampal.sourceforge.net/ptts.html

It contains a binary called ptts.exe that will speak text from standard input, so you can run it like this:

echo hello there | ptts.exe

Alternatively, you could use the following three line VBS script to get similar basic TTS:

'say.vbs
set s = CreateObject("SAPI.SpVoice")
s.Speak Wscript.Arguments(0), 3
s.WaitUntilDone(1000)

And you could invoke that from the command line like this:

cscript say.vbs "hello there"

If you go the script route, you'll probably want to find some more extensive code examples with a variable timeout and error handling.

Hope it helps.

昇り龍 2024-08-01 04:54:24

还有Balabolkahttp://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 "你好" 
      

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

There's also Balabolka: http://www.cross-plus-a.com/bconsole.htm
It has a command line tool balcon.exe. You can use it like this:

  1. List voices:

     balcon.exe -l
    
  2. Speak file:

     balcon.exe -n "IVONA 2 Jennifer" -f file.txt
    
  3. Speak from the command-line:

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

More command line options are available. I tried it on Ubuntu with SAPI5 installed in Wine. It works just fine.

拥抱没勇气 2024-08-01 04:54:24

如果找不到命令,您可以随时包装 System.Speech.Synthesis.SpeechSynthesizer 来自 .Net 3.0(不要忘记引用“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);
        }
    }
}

If you can't find a command you can always wrap the System.Speech.Synthesis.SpeechSynthesizer from .Net 3.0 (Don't forget to reference "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);
        }
    }
}
椵侞 2024-08-01 04:54:24

还有一种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"

There is a powershell way also:

Create a file called speak.ps1

param([string]$inputText)
Add-Type –AssemblyName System.Speech 
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$synth.Speak($inputText);

Then you can call it

.\speak.ps1 "I'm sorry Dave, I'm afraid I can't do that"
岁月苍老的讽刺 2024-08-01 04:54:24

我使用 wsay,它很小,更接近 macos 中的 say

I use wsay, it's small and more close to say in macos.

杯别 2024-08-01 04:54:24
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
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
拍不死你 2024-08-01 04:54:24

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

另一种选择是使用Cepstral。 它带有一个很好的命令行实用程序,听起来比 ms tts 好很多。

Your best approach is to write a small command line utility that will do it for you. It would not be a lot of work - just read text in and then use the ms tts library.

Another alternative is to use Cepstral. It comes with a nice command line utility and sounds light years better than the ms tts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文