使用python更改powershell tts命令叙述者
有人知道如何更改此tts powershell命令中的语音吗使用python更改powershell tts命令叙述者,python,windows,powershell,text-to-speech,Python,Windows,Powershell,Text To Speech,有人知道如何更改此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
-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()命令来实现它我的repo中脚本的快速翻译:
## 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")
:这很容易实现。只是一个专业提示,每个对象有两个参数集(
%
)。将自动枚举成员,因此不需要|%{$.Property}
:|%Property
。这同样适用于Where对象(?
),它可以在不使用过滤器脚本的情况下隐式执行操作:?{$\.Enabled}
变成|?启用了
@TheIncorrigible1这是一个相当古老的脚本,我刚从德语翻译过来,今天我会用不同的方式来编写。尽管如此,我还是想向其他人指出这些事情,因为普通人会继续按照他们一贯的方式来做,而不知道有新的功能可以让他们的代码更高效,或者至少,更容易阅读/digest.LotPings您有更简单的命令吗?或者只有一行吗?我正在使用pythons os.system()命令执行此命令。您希望如何选择语音?用固定的名字?请参见编辑后的答案。