Make Your Scripts Speak using PowerShell

email me

# Speech method 1 - Single phrase
Add-Type -AssemblyName System.speech
$speechObject = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speechObject.Speak('Hello, my name is Eddie!')
exit

# Speech method 2 - An array of messages
Add-Type -AssemblyName System.speech
$speechObject = New-Object System.Speech.Synthesis.SpeechSynthesizer

$strMessage = @("Hello, this is your computer talking.",
"I am the ghost in the machine",
"I'm sorry, I can't let you do that $env:USERNAME") | Get-Random
$speechObject.Speak($strMessage)
exit

# Speech method 3 - Speech from a file
Add-Type -AssemblyName System.speech
$speechObject = New-Object System.Speech.Synthesis.SpeechSynthesizer

$speechFile = "C:\Speech.csv"
$strMessage = (Get-Content $speechFile) | Get-Random
$speechObject.Speak($strMessage)