首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >powershell tts命令讲述人使用python更改

powershell tts命令讲述人使用python更改
EN

Stack Overflow用户
提问于 2018-07-04 02:42:32
回答 1查看 616关注 0票数 3

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

代码语言:javascript
复制
-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()命令来实现它

EN

回答 1

Stack Overflow用户

发布于 2018-07-04 04:12:14

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

代码语言:javascript
复制
## 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)

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

代码语言:javascript
复制
> .\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!

编辑:一个没有任何检查的最小脚本,

说一个固定的声音和一个固定的文本,可以用';‘连接成一行:

代码语言:javascript
复制
Add-Type -AssemblyName "System.Speech"
$speaker = new-object System.Speech.Synthesis.SpeechSynthesizer
$speaker.SelectVoice("Microsoft David Desktop")
$speaker.Speak("This is a text")
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51161126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档