Update speak-test.ps1

This commit is contained in:
Markus Fleschutz 2023-08-24 14:20:31 +02:00
parent b9153cd5da
commit 01939af228

View File

@ -4,15 +4,17 @@
.DESCRIPTION .DESCRIPTION
This PowerShell script performs a text-to-speech (TTS) test. This PowerShell script performs a text-to-speech (TTS) test.
.EXAMPLE .EXAMPLE
PS> ./speak-test PS> ./speak-test.ps1
📣 Let's begin with the default speed rate of 0 at the default volume of 100%.
...
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
function Speak { param([string]$Text) function Speak([string]$Text) {
write-output "'$Text'" Write-Output "📣 $Text"
[void]$Voice.speak("$Text") [void]$Voice.speak("$Text")
} }
@ -39,21 +41,22 @@ try {
$Voice.rate = $DefaultRate $Voice.rate = $DefaultRate
$Voice.volume = 100 $Voice.volume = 100
Speak("Let's try 100% volume") Speak("Let's try 100% volume.")
$Voice.volume = 75 $Voice.volume = 75
Speak("Let's try 75% volume") Speak("Let's try 75% volume.")
$Voice.volume = 50 $Voice.volume = 50
Speak("Let's try 50% volume") Speak("Let's try 50% volume.")
$Voice.volume = 25 $Voice.volume = 25
Speak("Let's try 25% volume") Speak("Let's try 25% volume.")
$Voice.volume = $DefaultVolume $Voice.volume = $DefaultVolume
$Voices = $Voice.GetVoices() $Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) { foreach ($OtherVoice in $Voices) {
$Voice.Voice = $OtherVoice $Voice.Voice = $OtherVoice
$Description = $OtherVoice.GetDescription() $Description = $OtherVoice.GetDescription()
Speak("Hi, I'm the voice called $Description") Speak("Hi, I'm the voice called $Description.")
} }
Speak("Thanks for your attention.")
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"