1
0
mirror of https://github.com/fleschutz/PowerShell.git synced 2024-12-17 04:00:46 +01:00
PowerShell/Scripts/speak-test.ps1

62 lines
1.5 KiB
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2021-10-16 16:50:10 +02:00
Performs a text-to-speech test
2021-10-04 21:29:23 +02:00
.DESCRIPTION
2021-10-16 16:50:10 +02:00
This script performs a text-to-speech (TTS) test.
2021-07-13 21:10:02 +02:00
.EXAMPLE
2021-09-27 08:35:45 +02:00
PS> ./speak-test
2021-08-29 17:50:03 +02:00
.NOTES
Author: Markus Fleschutz · License: CC0
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
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
}
2021-09-27 10:09:45 +02:00
exit 0 # success
2020-12-31 11:02:08 +01:00
} catch {
2021-09-16 20:19:10 +02:00
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
2020-12-31 11:02:08 +01:00
exit 1
}