【发布时间】:2019-06-03 08:51:19
【问题描述】:
调用SpeakSsmlAsync(Microsoft Speech SDK)时,返回如下错误信息:
> CANCELED: Reason=Error
> CANCELED: ErrorCode=BadRequest
> CANCELED: ErrorDetails=[HTTPAPI result code = HTTPAPI_OK. HTTP status code=400.]
> CANCELED: Did you update the subscription info?
重现步骤:
从以下位置下载快速入门示例 https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/text-to-speech/csharp-dotnet-windows
用自己的值替换订阅 ID 和区域,设置为活动 文档中描述的配置,清理和重建项目
-
启动程序并输入一些文本,例如“abracadabra”
--> 工作正常(使用
SpeakTextAsync) 将
SpeakTextAsync替换为SpeakSsmlAsync-
启动程序并输入一些文本
--> ErrorCode=BadRequest
-
使用正确的 SSML 代码重试,例如
<speak version="1.0" xmlns="https://www.w3.org/2001/10/synthesis" xml:lang="en-US">abracadabra</speak>"--> ErrorCode=BadRequest
系统
- .NET 框架 4.6.1
- Windows 10 内部版本 17134
- 服务区域 = “西欧”
代码
using System;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
namespace helloworld
{
class Program
{
private static string endpointSpeechKey = "<MyOwnServiceKey>";
private static string region = "westeurope";
public static async Task SynthesisToSpeakerAsync()
{
var config = SpeechConfig.FromSubscription(endpointSpeechKey, region);
using (var synthesizer = new SpeechSynthesizer(config))
{
Console.WriteLine("Type some text that you want to speak...");
Console.Write("> ");
string text = Console.ReadLine();
using (var result = await synthesizer.SpeakSsmlAsync(text))
{
if (result.Reason == ResultReason.SynthesizingAudioCompleted)
{
Console.WriteLine($"Speech synthesized to speaker for text [{text}]");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = SpeechSynthesisCancellationDetails.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?");
}
}
}
// This is to give some time for the speaker to finish playing back the audio
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
static void Main()
{
SynthesisToSpeakerAsync().Wait();
}
}
}
调试屏幕截图
【问题讨论】:
标签: c# .net speech-synthesis azure-cognitive-services azure-speech