PowerShell/scripts/speak-test.ps1

65 lines
1.7 KiB
PowerShell
Raw Normal View History

2023-10-31 11:25:11 +01: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
2022-01-30 10:49:30 +01:00
This PowerShell script performs a text-to-speech (TTS) test.
2021-07-13 21:10:02 +02:00
.EXAMPLE
2023-08-24 14:20:31 +02:00
PS> ./speak-test.ps1
📣 Let's begin with the default speed rate of 0 at the default volume of 100%.
...
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-01-30 10:49:30 +01:00
.NOTES
2022-09-06 21:42:04 +02:00
Author: Markus Fleschutz | License: CC0
2020-12-31 11:02:08 +01:00
#>
2023-08-24 14:20:31 +02:00
function Speak([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 {
2022-12-04 11:15:35 +01:00
$Voice = New-Object -ComObject SAPI.SPVoice
2020-12-31 11:25:41 +01:00
$DefaultVolume = $Voice.volume
$DefaultRate = $Voice.rate
2022-12-04 11:15:35 +01:00
Speak("Let's begin with the default speed rate of $DefaultRate at the default volume of $($DefaultVolume)%.")
2020-12-31 11:10:45 +01:00
$Voice.rate = -10
2022-12-04 11:15:35 +01:00
Speak("I'm speaking very, very slow at speed rate -10.")
2020-12-31 11:25:41 +01:00
$Voice.rate = -5
2022-12-04 11:15:35 +01:00
Speak("I'm speaking very slow at speed rate -5.")
2021-01-02 13:40:18 +01:00
$Voice.rate = -3
2022-12-04 11:15:35 +01:00
Speak("I'm speaking slow at rate -3.")
2021-01-02 13:40:18 +01:00
$Voice.rate = 0
2022-12-04 11:15:35 +01:00
Speak("I'm speaking quite normal at speed rate 0.")
2020-12-31 11:25:41 +01:00
$Voice.rate = 2
2022-12-04 11:15:35 +01:00
Speak("I'm speaking fast at speed rate 2.")
2020-12-31 11:25:41 +01:00
$Voice.rate = 5
2022-12-04 11:15:35 +01:00
Speak("I'm speaking very fast at speed rate 5.")
2020-12-31 11:25:41 +01:00
$Voice.rate = 10
2022-12-04 11:15:35 +01:00
Speak("I'm speaking very, very fast at speed rate 10.")
2020-12-31 11:25:41 +01:00
$Voice.rate = $DefaultRate
2020-12-31 11:10:45 +01:00
$Voice.volume = 100
2023-08-24 14:20:31 +02:00
Speak("Let's try 100% volume.")
2020-12-31 11:25:41 +01:00
$Voice.volume = 75
2023-08-24 14:20:31 +02:00
Speak("Let's try 75% volume.")
2020-12-31 11:10:45 +01:00
$Voice.volume = 50
2023-08-24 14:20:31 +02:00
Speak("Let's try 50% volume.")
2020-12-31 11:25:41 +01:00
$Voice.volume = 25
2023-08-24 14:20:31 +02: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()
2023-08-24 14:20:31 +02:00
Speak("Hi, I'm the voice called $Description.")
2020-12-31 11:02:08 +01:00
}
2023-08-24 14:20:31 +02:00
Speak("Thanks for your attention.")
2021-09-27 10:09:45 +02:00
exit 0 # success
2020-12-31 11:02:08 +01:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-31 11:02:08 +01:00
exit 1
}