PowerShell/Scripts/speak-test.ps1

63 lines
1.4 KiB
PowerShell
Raw Normal View History

2021-08-26 10:46:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
speak-test.ps1
.DESCRIPTION
2021-08-03 15:53:57 +02:00
Performs a test speak by text-to-speech (TTS)
2021-07-13 21:10:02 +02:00
.EXAMPLE
PS> .\speak-test.ps1
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
2021-08-03 15:53:57 +02:00
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-05-02 21:30:48 +02:00
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-31 11:02:08 +01:00
exit 1
}