Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (var recognizer = new SpeechRecognizer(config, AudioConfig.FromWavFileInput(@"/Full/Path/To/File.wav")))
- {
- recognizer.Recognizing += (s, e) =>
- {
- Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
- };
- recognizer.Recognized += (s, e) =>
- {
- if (e.Result.Reason == ResultReason.RecognizedSpeech)
- {
- Console.WriteLine(e.Result.Text);
- }
- else if (e.Result.Reason == ResultReason.NoMatch)
- {
- Console.WriteLine($"NOMATCH: Speech could not be recognized.");
- }
- else if (e.Result.Reason == ResultReason.Canceled)
- {
- var cancellation = CancellationDetails.FromResult(e.Result);
- Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
- if (cancellation.Reason == CancellationReason.Error)
- {
- Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
- Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
- Console.WriteLine($"CANCELED: Did you update the subscription info?");
- }
- }
- };
- recognizer.Canceled += (s, e) =>
- {
- Console.WriteLine($"CANCELED: Reason={e.Reason}");
- if (e.Reason == CancellationReason.Error)
- {
- Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
- Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
- Console.WriteLine($"CANCELED: Did you update the subscription info?");
- }
- };
- recognizer.SessionStarted += (s, e) =>
- {
- Console.WriteLine("nSession started event.");
- };
- recognizer.SessionStopped += (s, e) =>
- {
- Console.WriteLine("nSession stopped event.");
- Console.WriteLine("nStop recognition.");
- };
- await recognizer.StartContinuousRecognitionAsync();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement