Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. using (var recognizer = new SpeechRecognizer(config, AudioConfig.FromWavFileInput(@"/Full/Path/To/File.wav")))
  2. {
  3. recognizer.Recognizing += (s, e) =>
  4. {
  5. Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
  6. };
  7.  
  8. recognizer.Recognized += (s, e) =>
  9. {
  10. if (e.Result.Reason == ResultReason.RecognizedSpeech)
  11. {
  12. Console.WriteLine(e.Result.Text);
  13. }
  14. else if (e.Result.Reason == ResultReason.NoMatch)
  15. {
  16. Console.WriteLine($"NOMATCH: Speech could not be recognized.");
  17. }
  18. else if (e.Result.Reason == ResultReason.Canceled)
  19. {
  20. var cancellation = CancellationDetails.FromResult(e.Result);
  21. Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
  22.  
  23. if (cancellation.Reason == CancellationReason.Error)
  24. {
  25. Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
  26. Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
  27. Console.WriteLine($"CANCELED: Did you update the subscription info?");
  28. }
  29. }
  30. };
  31.  
  32. recognizer.Canceled += (s, e) =>
  33. {
  34. Console.WriteLine($"CANCELED: Reason={e.Reason}");
  35.  
  36. if (e.Reason == CancellationReason.Error)
  37. {
  38. Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
  39. Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
  40. Console.WriteLine($"CANCELED: Did you update the subscription info?");
  41. }
  42. };
  43.  
  44. recognizer.SessionStarted += (s, e) =>
  45. {
  46. Console.WriteLine("nSession started event.");
  47. };
  48.  
  49. recognizer.SessionStopped += (s, e) =>
  50. {
  51. Console.WriteLine("nSession stopped event.");
  52. Console.WriteLine("nStop recognition.");
  53. };
  54.  
  55. await recognizer.StartContinuousRecognitionAsync();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement