-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOut-TextToSpeech.ps1
24 lines (23 loc) · 1 KB
/
Out-TextToSpeech.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
# A function which takes a string as input and converts it to speech
# Requires the System.Speech assembly
# Possible voices are:
# - Microsoft David Desktop
# - Microsoft Zira Desktop
# For list of installed voices, run the following:
# Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Speech\Voices\Tokens\*" | Get-ItemProperty | Select -ExpandProperty "(default)"
Param(
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)]
[string]$Text
, [Parameter(Mandatory = $False, Position = 1, ValueFromPipeline = $False)]
[string]$Voice = "Zira"
, [Parameter(Mandatory = $False, Position = 2, ValueFromPipeline = $False)]
[int]$Rate = 2
, [Parameter(Mandatory = $False, Position = 3, ValueFromPipeline = $False)]
[int]$Volume = 100
)
Add-Type -AssemblyName System.Speech
$speechSynthesizer = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speechSynthesizer.SelectVoice("Microsoft $Voice Desktop")
$speechSynthesizer.Rate = $Rate
$speechSynthesizer.Volume = $Volume
$speechSynthesizer.Speak($Text)