Skip to content

Instantly share code, notes, and snippets.

@lazywinadmin
Created December 10, 2014 21:20
Show Gist options
  • Save lazywinadmin/51619a0e47f4c8e7a8b7 to your computer and use it in GitHub Desktop.
Save lazywinadmin/51619a0e47f4c8e7a8b7 to your computer and use it in GitHub Desktop.
Show how to use the Speech feature in Windows using PowerShell
# Technique one: COM Object Version
$s = New-Object -ComObject SAPI.SPVoice
$s.Speak("You are Re-Hired!")
# Technique two: NET Object Version
Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
# Play a sound
$speak.Speak("Pomme de terre")
# Record the sound in a WAV file
$speak.SetOutputToWaveFile("C:\users\$env:username\Desktop\test.wav")
$speak.Speak("Pomme de terre?")
$speak.Dispose() # this stop and save the wav file
#Voices
$speak.voice # Voice Currently in use
$speak.GetInstalledVoices().VoiceInfo #list of Voices available
#Change the Voice
$speak.SelectVoice('Microsoft David Desktop')
$speak.SelectVoice('Microsoft Hazel Desktop')
$speak.SelectVoice('Microsoft Zira Desktop')
#Change Rate and Volume
$speak.rate = -10 #slow
$speak.rate = 10 #fast
$speak.Volume = 100
$speak.Speak("Pomme de terre")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment