Рет қаралды 305
Learn how to create a PowerShell script that can listen to your voice and respond with spoken words.
01:37 Setting up Speech Synthesis
04:01 Configuring Speech Recognition
06:22 Implementing the Script Logic
09:14 Running the Script
*The Script Used in This Tutorial*
Adapted from outnull.wordpr...
Allow PowerShell to Speak
Add-Type -AssemblyName System.Speech
$Talk = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer
Setup the Speech Recognition Engine Object
$SpeechRecognitionEngine = New-Object -TypeName System.Speech.Recognition.SpeechRecognitionEngine
Define the verbal commands to be supported by the script
$Grammar = New-Object -TypeName System.Speech.Recognition.GrammarBuilder
$Grammar.Append(“Hello”);
$SpeechRecognitionEngine.LoadGrammar($Grammar);
$Grammar = New-Object -TypeName System.Speech.Recognition.GrammarBuilder
$Grammar.Append(“Exit”);
$SpeechRecognitionEngine.LoadGrammar($Grammar);
$SpeechRecognitionEngine.InitialSilenceTimeout = 15
$SpeechRecognitionEngine.SetInputToDefaultAudioDevice();
$CMDBoolean = $false;
While ($CMDBoolean -eq $False) {
$SpeechRecognize = $SpeechRecognitionEngine.Recognize();
$Conf = $SpeechRecognize.Confidence;
$MyWords = $SpeechRecognize.text;
if ($MyWords -match “hello” -and [double]$conf -gt 0.85) {
$Talk.Speak(“Hello”);
}
if ($MyWords -match “exit” -and [double]$conf -gt 0.85) {
$Talk.Speak(“Goodbye”);
$CMDBoolean = $True;
}
}
Brien Posey is a bestselling technology author, speaker, and 21x Microsoft MVP. In addition to his ongoing work in IT, Posey has trained as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.
For daily news, analysis, opinions and how-to’s about the IT industry, visit us at ITPro Today: www.itprotoday...
Music by AudioCoffee on Pixabay
#powershellscripting #voicerecognition #texttospeech #powershell