luca ravera

luca ravera

  • NA
  • 2
  • 2.7k

voice recognition request complete code

Jan 5 2019 2:52 PM
Greetings to all, I ask you for courtesy if you can help me, I just started using C #, I'm exploring the voice recognition so for study and curiosity, The program listens my voice and write result  in the cmd Windows prompt , I have to get that if the voice result is the word open Browser NaMe  is done starting the browserprocess .
read the cmd result and if result corresponds  for example  MyBrowser.exe  program start Browser  Mybrowser.exe.
thank you so much for your help . 
  1. using System;  
  2. using System.ComponentModel;  
  3. using System.Diagnostics;  
  4. using System.Threading.Tasks;  
  5. using Microsoft.CognitiveServices.Speech;  
  6.   
  7.   
  8. namespace helloworld  
  9. {  
  10.     class Program  
  11.     {  
  12.         public static async Task RecognizeSpeechAsync()  
  13.         {  
  14.              
  15.             // Creates an instance of a speech config with specified subscription key and service region.  
  16.             // Replace with your own subscription key and service region (e.g., "westus").  
  17.             var config = SpeechConfig.FromSubscription("mykey""westus");  
  18.   
  19.             // Creates a speech recognizer.  
  20.             using (var recognizer = new SpeechRecognizer(config))  
  21.   
  22.             {  
  23.                 Console.WriteLine("Say something...");  
  24.   
  25.                 // Performs recognition. RecognizeOnceAsync() returns when the first utterance has been recognized,  
  26.                 // so it is suitable only for single shot recognition like command or query. For long-running  
  27.                 // recognition, use StartContinuousRecognitionAsync() instead.  
  28.                 var result = await recognizer.RecognizeOnceAsync();  
  29.   
  30.                 // Checks result.  
  31.                 if (result.Reason == ResultReason.RecognizedSpeech)  
  32.                 {  
  33.                     Console.WriteLine($"We recognized: {result.Text}");  
  34.                                               
  35.                 }  
  36.   
  37.                 else if (result.Reason == ResultReason.NoMatch)  
  38.                 {  
  39.                     Console.WriteLine($"NOMATCH: Speech could not be recognized.");  
  40.                 }  
  41.                 else if (result.Reason == ResultReason.Canceled)  
  42.                 {  
  43.                     var cancellation = CancellationDetails.FromResult(result);  
  44.                     Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");  
  45.   
  46.                     if (cancellation.Reason == CancellationReason.Error)  
  47.                     {  
  48.                         Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");  
  49.                         Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");  
  50.                         Console.WriteLine($"CANCELED: Did you update the subscription info?");  
  51.                     }  
  52.                 }  
  53.             }  
  54.         }  
  55.   
  56.         static void Main()  
  57.         {  
  58.             RecognizeSpeechAsync().Wait();  
  59.             Console.WriteLine("Please press a key to continue.");  
  60.             Console.ReadLine();  
  61.         }  
  62.     }  
  63. }  
 
 
 

Answers (1)