-
Notifications
You must be signed in to change notification settings - Fork 73
/
Out-Voice.ps1
107 lines (92 loc) · 2.96 KB
/
Out-Voice.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Function Out-Voice {
<#
.SYNOPSIS
Used to allow PowerShell to speak to you or sends data to a WAV file for later listening.
.DESCRIPTION
Used to allow PowerShell to speak to you or sends data to a WAV file for later listening.
.PARAMETER InputObject
Data that will be spoken or sent to a WAV file.
.PARAMETER Rate
Sets the speaking rate
.PARAMETER Volume
Sets the output volume
.PARAMETER ToWavFile
Append output to a Waveform audio format file in a specified format
.NOTES
Name: Out-Voice
Author: Boe Prox
DateCreated: 12/4/2013
To Do:
-Support for other installed voices
.EXAMPLE
"This is a test" | Out-Voice
Description
-----------
Speaks the string that was given to the function in the pipeline.
.EXAMPLE
"Today's date is $((get-date).toshortdatestring())" | Out-Voice
Description
-----------
Says todays date
.EXAMPLE
"Today's date is $((get-date).toshortdatestring())" | Out-Voice -ToWavFile "C:\temp\test.wav"
Description
-----------
Says todays date
#>
[cmdletbinding(
)]
Param (
[parameter(ValueFromPipeline='True')]
[string[]]$InputObject,
[parameter()]
[ValidateRange(-10,10)]
[Int]$Rate,
[parameter()]
[ValidateRange(1,100)]
$Volume,
[parameter()]
[string]$ToWavFile
)
Begin {
$Script:parameter = $PSBoundParameters
Write-Verbose "Listing parameters being used"
$PSBoundParameters.GetEnumerator() | ForEach {
Write-Verbose "$($_)"
}
Write-Verbose "Loading assemblies"
Add-Type -AssemblyName System.speech
Write-Verbose "Creating Speech object"
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
Write-Verbose "Setting volume"
If ($PSBoundParameters['Volume']) {
$speak.Volume = $PSBoundParameters['Volume']
} Else {
Write-Verbose "No volume given, using default: 100"
$speak.Volume = 100
}
Write-Verbose "Setting speech rate"
If ($PSBoundParameters['Rate']) {
$speak.Rate = $PSBoundParameters['Rate']
} Else {
Write-Verbose "No rate given, using default: -2"
$speak.rate = -2
}
If ($PSBoundParameters['WavFile']) {
Write-Verbose "Saving speech to wavfile: $wavfile"
$speak.SetOutputToWaveFile($wavfile)
}
}
Process {
ForEach ($line in $inputobject) {
Write-Verbose "Speaking: $line"
$Speak.SpeakAsync(($line | Out-String)) | Out-Null
}
}
End {
If ($PSBoundParameters['ToWavFile']) {
Write-Verbose "Performing cleanup"
$speak.dispose()
}
}
}