【问题标题】:ms speech from command line来自命令行的 ms 语音
【发布时间】:2010-11-05 15:42:28
【问题描述】:

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

【问题讨论】:

标签: cmd text-to-speech


【解决方案1】:

我在主题上的 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 @987654324@

【讨论】:

  • 哇,这是一个很棒的答案
  • 当我运行 mshta 命令时,我得到一个拒绝访问响应。
  • @ColorCodin 听起来像是,您需要在提升的环境中运行它。就像以管理员身份运行“cmd.exe”或为所有用户授予对 mshta.exe 的访问权限。
  • 如何在 Windows 上使用 mshta.exe 更改音频输出设备?
  • @MacMarde 你会在 stackoverflow 中搜索“vbscript 更改音频输入”或类似的东西
【解决方案2】:

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

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

希望对你有帮助。

【讨论】:

  • 您可以安装彼得的文本转语音程序Jampal,然后执行ptts.vbs文件播放文本文件。您选择的声音需要已经安装在 Windows 中。示例:C:\Program Files\Jampal>cscript "c:\program files\jampal\ptts.vbs" -voice "IVONA Amy" < raven.txtC:\Program Files\Jampal>cscript "c:\program files\jampal\ptts.vbs" -voice "IVONA Jennifer" < raven.txt
【解决方案3】:

如果找不到命令,您可以随时将 .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);
        }
    }
}

【讨论】:

  • 使用 github.com/oleg-shilo/cs-script 这可以在命令行中使用,无需编译也无需 Visual Studio
【解决方案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"

【讨论】:

    【解决方案5】:

    还有 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。它工作得很好。

    【讨论】:

      【解决方案6】:
      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
      

      【讨论】:

        【解决方案7】:

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

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

        【讨论】:

          猜你喜欢
          • 2010-12-11
          • 2016-08-03
          • 2017-08-30
          • 2021-05-23
          • 1970-01-01
          • 2021-08-13
          相关资源
          最近更新 更多