Added speak-english.ps1

This commit is contained in:
Markus Fleschutz
2021-02-08 19:32:45 +01:00
parent d362968965
commit a5ba0c2d34
3 changed files with 31 additions and 0 deletions

29
Scripts/speak-english.ps1 Executable file
View File

@ -0,0 +1,29 @@
#!/snap/bin/powershell
<#
.SYNTAX ./speak-english.ps1 [<text>]
.DESCRIPTION speaks the given text with an English text-to-speech (TTS) voice
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($Text = "")
try {
$Voice = new-object -ComObject SAPI.SPVoice
$Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) {
$Description = $OtherVoice.GetDescription()
if ($Description -like "*- English*") {
write-progress "$Text"
$Voice.Voice = $OtherVoice
[void]$Voice.Speak($Text)
write-progress -complete ""
exit 0
}
}
write-error "Sorry, no English text-to-speech (TTS) voice found"
exit 1
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}