在机器人框架C#中使用Bing Speech API,可以通过以下步骤实现:
以下是一个示例代码:
using Microsoft.CognitiveServices.Speech;
class Program
{
static async Task Main(string[] args)
{
// 创建SpeechRecognizer对象
var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
using (var recognizer = new SpeechRecognizer(config))
{
// 订阅Recognized事件
recognizer.Recognized += (s, e) =>
{
if (e.Result.Reason == ResultReason.RecognizedSpeech)
{
Console.WriteLine($"识别结果:{e.Result.Text}");
}
};
// 开始识别
await recognizer.StartContinuousRecognitionAsync();
// 按任意键停止识别
Console.WriteLine("按任意键停止识别...");
Console.ReadKey();
// 停止识别
await recognizer.StopContinuousRecognitionAsync();
}
}
}
领取专属 10元无门槛券
手把手带您无忧上云