-
-
Notifications
You must be signed in to change notification settings - Fork 542
Expand file tree
/
Copy pathspeak-english.ps1
More file actions
executable file
·34 lines (30 loc) · 776 Bytes
/
speak-english.ps1
File metadata and controls
executable file
·34 lines (30 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<#
.SYNOPSIS
Speaks text in English
.DESCRIPTION
This PowerShell script speaks the given text with an English text-to-speech (TTS) voice.
.PARAMETER text
Specifies the English text to speak
.EXAMPLE
PS> ./speak-english.ps1 Hi
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
#requires -version 5.1
param([string]$text = "")
try {
if ($text -eq "") { $text = Read-Host "Enter the English text to speak" }
$TTS = New-Object -ComObject SAPI.SPVoice
foreach ($voice in $TTS.GetVoices()) {
if ($voice.GetDescription() -like "*- English*") {
$TTS.Voice = $voice
}
}
[void]$TTS.Speak($text)
exit 0 # success
} catch {
"⚠️ ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}