PowerShell/Scripts/speak-test.ps1

56 lines
1.4 KiB
PowerShell
Raw Normal View History

2020-12-31 11:02:08 +01:00
<#
2021-04-07 15:17:49 +02:00
.SYNTAX speak-test.ps1
2021-03-22 20:10:18 +01:00
.DESCRIPTION performs a test speak by text-to-speech (TTS)
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
2020-12-31 11:02:08 +01:00
#>
2021-01-02 13:40:18 +01:00
function Speak { param([string]$Text)
write-output "'$Text'"
2021-01-09 16:40:46 +01:00
[void]$Voice.speak("$Text")
2021-01-02 13:40:18 +01:00
}
2020-12-31 11:02:08 +01:00
try {
$Voice = new-object -ComObject SAPI.SPVoice
2020-12-31 11:25:41 +01:00
$DefaultVolume = $Voice.volume
$DefaultRate = $Voice.rate
2021-01-02 13:40:18 +01:00
Speak("This is the default voice with default volume $DefaultVolume and speed $DefaultRate")
2020-12-31 11:10:45 +01:00
$Voice.rate = -10
2021-01-02 13:40:18 +01:00
Speak("Let's speak very, very slow")
2020-12-31 11:25:41 +01:00
$Voice.rate = -5
2021-01-02 13:40:18 +01:00
Speak("Let's speak very slow")
$Voice.rate = -3
Speak("Let's speak slow")
$Voice.rate = 0
Speak("Let's speak normal")
2020-12-31 11:25:41 +01:00
$Voice.rate = 2
2021-01-02 13:40:18 +01:00
Speak("Let's speak fast")
2020-12-31 11:25:41 +01:00
$Voice.rate = 5
2021-01-02 13:40:18 +01:00
Speak("Let's speak very fast")
2020-12-31 11:25:41 +01:00
$Voice.rate = 10
2021-01-02 13:40:18 +01:00
Speak("Let's speak very, very fast")
2020-12-31 11:25:41 +01:00
$Voice.rate = $DefaultRate
2020-12-31 11:10:45 +01:00
$Voice.volume = 100
2021-01-02 13:40:18 +01:00
Speak("Let's try 100% volume")
2020-12-31 11:25:41 +01:00
$Voice.volume = 75
2021-01-02 13:40:18 +01:00
Speak("Let's try 75% volume")
2020-12-31 11:10:45 +01:00
$Voice.volume = 50
2021-01-02 13:40:18 +01:00
Speak("Let's try 50% volume")
2020-12-31 11:25:41 +01:00
$Voice.volume = 25
2021-01-02 13:40:18 +01:00
Speak("Let's try 25% volume")
2020-12-31 11:25:41 +01:00
$Voice.volume = $DefaultVolume
2020-12-31 11:02:08 +01:00
$Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) {
$Voice.Voice = $OtherVoice
2021-01-02 13:40:18 +01:00
$Description = $OtherVoice.GetDescription()
Speak("Hi, I'm the voice called $Description")
2020-12-31 11:02:08 +01:00
}
exit 0
} catch {
2021-02-16 10:03:20 +01:00
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-31 11:02:08 +01:00
exit 1
}