using System; using System.Threading.Tasks; using Microsoft.CognitiveServices.Speech; using Microsoft.CognitiveServices.Speech.Audio; namespace demo { class Program { public static async Task RecognizeSpeechAsync() { var config = SpeechConfig.FromHost(new Uri(""ws://azurecontainer_generated_ip:5000/")); using (var audioConfig = AudioConfig.FromWavFileInput(@"C:\\Users\\myname\\Downloads\\audio\\test.wav")) using (var recognizer = new SpeechRecognizer(config, audioConfig)) { Console.WriteLine("Starting..."); var result = await recognizer.RecognizeOnceAsync(); if (result.Reason == ResultReason.RecognizedSpeech) { Console.WriteLine($"We recognized: {result.Text}"); } else if (result.Reason == ResultReason.NoMatch) { Console.WriteLine($"NOMATCH: Speech could not be recognized."); } else if (result.Reason == ResultReason.Canceled) { var cancellation = CancellationDetails.FromResult(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?"); } } } } static async Task Main() { await RecognizeSpeechAsync(); Console.WriteLine("Please press to continue."); Console.ReadLine(); } } }