【问题标题】:powershell tts command narrator change using python使用python的powershell tts命令旁白更改
【发布时间】:2018-12-12 03:42:30
【问题描述】:

有人知道如何在这个 tts powershell 命令中改变声音吗?

-Powershell Command Add-Type -AssemblyName System.Speech
$Speaker = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
$Speaker.Speak('oh my god, I can now talk; it''s amazing!')

并且它需要尽可能小,因为我使用 pythons os.system() 命令来实现它

【问题讨论】:

标签: python windows powershell text-to-speech


【解决方案1】:

我的仓库中的一个脚本的快速翻译:

## SelVoiceSpeak.ps1
Add-Type -AssemblyName "System.Speech"
$speaker = new-object System.Speech.Synthesis.SpeechSynthesizer
$speaker.SetOutputToDefaultAudioDevice()
write-host "These voices are installed:`r`n" -ForegroundColor Yellow -BackgroundColor Black
$cntr = 0;
$voices = $speaker.GetInstalledVoices() | Where Enabled | ForEach VoiceInfo
$voices | %{$cntr++;write-host "[$cntr] $($_.Name)" -ForegroundColor Green}
$choice = Read-Host "`r`nChoose a name [1-$($voices.length)]"
if ($choice -gt 0 -and $choice -le $voices.length){
    $voice = $voices[$choice -1].Name
    $speaker.SelectVoice($voice)
} else {
    write-Host "no valid choice" -ForegroundColor Red
    exit
}
$text = Read-Host "`r`nEnter text to speak"
write-host "`r`nspeaking now!" -BackgroundColor DarkCyan -ForegroundColor White
$speaker.Speak($text)

相当难看的颜色,示例输出:

> .\SelVoiceSpeak.ps1
These voices are installed:

[1] Microsoft Hedda Desktop
[2] Microsoft Zira Desktop

Choose a name [1-2]: 2

Enter text to speak: hello world!

speaking now!

编辑:无需任何检查的最小脚本,
说一个固定的声音和一个固定的文本,可以与';'连接一行:

Add-Type -AssemblyName "System.Speech"
$speaker = new-object System.Speech.Synthesis.SpeechSynthesizer
$speaker.SelectVoice("Microsoft David Desktop")
$speaker.Speak("This is a text")

【讨论】:

  • 只是一个专业提示,ForEach-Object (%) 有两个参数集。一个会自动枚举成员,所以| % { $_.Property } 是不必要的:| % PropertyWhere-Object (?) 也是如此,它可以在没有 filterscript 的情况下隐式执行操作:| ? {$_.Enabled} 变为 | ? Enabled
  • @TheIncorrigible1 那是一个相当古老的脚本,我只是从德语翻译过来的,我今天会换个方式来写。
  • 即便如此,我还是想向其他看到它的人指出这些事情,因为普通人会继续按照他们一贯的方式做事,而不知道有新功能可以提高他们的代码效率,或者至少更容易阅读/消化。
  • LotPings 你有一个更简单的命令,还是有一行它只是我正在使用 pythons os.system() 命令执行这个
  • 你想如何选择声音?用固定的名字?请参阅编辑后的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
  • 2022-01-25
  • 2015-05-17
  • 1970-01-01
  • 2016-07-02
相关资源
最近更新 更多