Быстрый перевод скрипта в моем репо:
## 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")