PowerShell/docs/speak-test.md

87 lines
2.2 KiB
Markdown
Raw Normal View History

2024-01-25 13:37:12 +01:00
Script: *speak-test.ps1*
========================
2022-11-17 20:02:26 +01:00
speak-test.ps1
2021-10-17 14:33:27 +02:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2021-10-17 14:33:27 +02:00
```powershell
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
Performs a text-to-speech test
.DESCRIPTION
This PowerShell script performs a text-to-speech (TTS) test.
.EXAMPLE
2023-09-01 17:53:03 +02:00
PS> ./speak-test.ps1
📣 Let's begin with the default speed rate of 0 at the default volume of 100%.
...
2022-11-17 20:02:26 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2023-09-01 17:53:03 +02:00
function Speak([string]$Text) {
Write-Output "📣 $Text"
2022-11-17 20:02:26 +01:00
[void]$Voice.speak("$Text")
}
try {
2023-05-26 12:20:18 +02:00
$Voice = New-Object -ComObject SAPI.SPVoice
2022-11-17 20:02:26 +01:00
$DefaultVolume = $Voice.volume
$DefaultRate = $Voice.rate
2023-05-26 12:20:18 +02:00
Speak("Let's begin with the default speed rate of $DefaultRate at the default volume of $($DefaultVolume)%.")
2022-11-17 20:02:26 +01:00
$Voice.rate = -10
2023-05-26 12:20:18 +02:00
Speak("I'm speaking very, very slow at speed rate -10.")
2022-11-17 20:02:26 +01:00
$Voice.rate = -5
2023-05-26 12:20:18 +02:00
Speak("I'm speaking very slow at speed rate -5.")
2022-11-17 20:02:26 +01:00
$Voice.rate = -3
2023-05-26 12:20:18 +02:00
Speak("I'm speaking slow at rate -3.")
2022-11-17 20:02:26 +01:00
$Voice.rate = 0
2023-05-26 12:20:18 +02:00
Speak("I'm speaking quite normal at speed rate 0.")
2022-11-17 20:02:26 +01:00
$Voice.rate = 2
2023-05-26 12:20:18 +02:00
Speak("I'm speaking fast at speed rate 2.")
2022-11-17 20:02:26 +01:00
$Voice.rate = 5
2023-05-26 12:20:18 +02:00
Speak("I'm speaking very fast at speed rate 5.")
2022-11-17 20:02:26 +01:00
$Voice.rate = 10
2023-05-26 12:20:18 +02:00
Speak("I'm speaking very, very fast at speed rate 10.")
2022-11-17 20:02:26 +01:00
$Voice.rate = $DefaultRate
$Voice.volume = 100
2023-09-01 17:53:03 +02:00
Speak("Let's try 100% volume.")
2022-11-17 20:02:26 +01:00
$Voice.volume = 75
2023-09-01 17:53:03 +02:00
Speak("Let's try 75% volume.")
2022-11-17 20:02:26 +01:00
$Voice.volume = 50
2023-09-01 17:53:03 +02:00
Speak("Let's try 50% volume.")
2022-11-17 20:02:26 +01:00
$Voice.volume = 25
2023-09-01 17:53:03 +02:00
Speak("Let's try 25% volume.")
2022-11-17 20:02:26 +01:00
$Voice.volume = $DefaultVolume
$Voices = $Voice.GetVoices()
foreach ($OtherVoice in $Voices) {
$Voice.Voice = $OtherVoice
$Description = $OtherVoice.GetDescription()
2023-09-01 17:53:03 +02:00
Speak("Hi, I'm the voice called $Description.")
2022-11-17 20:02:26 +01:00
}
2023-09-01 17:53:03 +02:00
Speak("Thanks for your attention.")
2022-11-17 20:02:26 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2024-05-19 10:25:56 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of speak-test.ps1 as of 05/19/2024 10:25:26)*