Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python更改powershell tts命令叙述者_Python_Windows_Powershell_Text To Speech - Fatal编程技术网

使用python更改powershell tts命令叙述者

使用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

有人知道如何更改此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()命令来实现它

我的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()命令执行此命令。您希望如何选择语音?用固定的名字?请参见编辑后的答案。