WebSocket升级失败,并显示身份验证错误(401)。请检查正确的订阅密钥(或授权令牌)和区域名称
public static async Task RecognizeSpeechAsync()
{
var config = SpeechConfig.FromSubscription("05b60e36-d7bc-428f-a48a-684475160081", "westus");
//var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
using(var audioInput = AudioConfig.FromWavFileInput(@"D:\KM\Azure\Hands-OnProjects\Speech\SpeechRecognition\file_example_WAV_1MG.wav"))
{
using(var recognizer = new SpeechRecognizer(config, audioInput))
{
Console.WriteLine("Recognizing first result...");
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?");
}
}
}
}//end of using stat
}//end of RecognizeSpeechAsync