-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathPowerSpeak.ps1
More file actions
97 lines (76 loc) · 1.84 KB
/
PowerSpeak.ps1
File metadata and controls
97 lines (76 loc) · 1.84 KB
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
function PowerSpeak
{
<#
.SYNOPSIS
PowerSpeak is a PowerShell interface for the Windows Speech interface that exists since Windows XP.
It is not an interface for Cortana.
TODO: fix that the user is presented the Speech Wizard after re-login.
Function: PowerSpeak
Author: Marc Smeets
.DESCRIPTION
PowerSpeak can be used for sending text to speech using the Windows Speech interface.
.PARAMETER Test
Test if system is capable of speaking.
.PARAMETER Speak
The text to speak. Enclose with quotes if more than 1 word.
.EXAMPLE
PS > PowerSpeak -Test
This will try to start the Windows Speech interface and display its state.
.EXAMPLE
PS > PowerSpeak Hello
This will speak the single word "Hello".
.EXAMPLE
PS > PowerSpeak Hello -Volume 50
This will speak the single word "Hello" at half volume.
If Volume is not specified it will be set to max and reset to previous value when done speaking.
.EXAMPLE
PS > PowerSpeak "Look! It's moving. It's alive. It's alive... IT'S ALIVE!"
Using quotes we can speak sentences.
.LINK
http://www.outflank.nl
#>
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory = $False)]
[String]
$Speak,
[Switch]$Test,
[Parameter(Mandatory = $False)]
[ValidateRange(0,100)]
[Int]
$Volume=100
)
if ($Test)
{
$PowerSpeak|gm
}
if ($Speak)
{
try
{
$oldvolume = $PowerSpeak.volume
$PowerSpeak.Volume = $Volume
$PowerSpeak.speak($Speak)
$PowerSpeak.volume = $oldvolume
}
catch
{
$PowerSpeak.volume = $oldvolume
write-host "Error sending speak command."
}
}
}
try
{
add-type -assemblyname system.speech
$PowerSpeak = New-Object System.Speech.Synthesis.SpeechSynthesizer
}
catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
write-host "Error loading Windows Speech interface."
write-host $errormessage
write-host $faileditem
break
}