-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathOut-Loud.ps1
54 lines (43 loc) · 1.31 KB
/
Out-Loud.ps1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function Out-Loud(){
Param(
#Message
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
[ValidateNotNull()]
[String[]]$Speech,
#Voice
[ValidateSet('David', 'Zira', 'Hazel')]
[String]$Voice = 'Zira',
#Volume
[ValidateRange(0,100)]
[int]$Volume=100,
#Rate
[ValidateRange(-10,10)]
[int]$Rate=-1,
#Don't wait for promt
[switch]$Async,
#Print text to screen
[switch]$Print
)
Begin{
#add speech type and create speech object
Add-Type -AssemblyName System.speech
$SpeechSynth = New-Object System.Speech.Synthesis.SpeechSynthesizer
#adjust voice settings
$SpeechSynth.SelectVoice("Microsoft $voice Desktop")
$SpeechSynth.volume=$Volume
$SpeechSynth.Rate=$Rate
}
Process{
# Print text to screen if -Print
if($Print){$Speech}
# Don't wait for prompt if -Async
if($Async){$SpeechSynth.SpeakAsync($Speech) | Out-Null}
# or just say it...
else{$SpeechSynth.Speak($Speech)}
}
End{}
}
#create alias for cmdlet
set-alias Say Out-Loud
# 'Hello World' | Out-Loud
# Say 'Hello World' -Voice David -Volume 100 -Rate -3 -Async