c# - SpeakSsmlAsync 返回 BadRequest

标签 c# .net speech-synthesis azure-cognitive-services azure-speech

调用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?

重现步骤:

  1. 从以下位置下载快速入门示例 https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/text-to-speech/csharp-dotnet-windows

  2. 用自己的值替换订阅 ID 和区域,设置事件 文档中描述的配置,清理和重建项目

  3. 启动程序并输入一些文本,如“abracadabra”

    --> 工作正常(使用 SpeakTextAsync )

  4. 替换SpeakTextAsyncSpeakSsmlAsync

  5. 启动程序并输入一些文本

    --> ErrorCode=BadRequest

  6. 使用适当的 SSML 代码重试 <speak version="1.0" xmlns="https://www.w3.org/2001/10/synthesis" xml:lang="en-US">abracadabra</speak> "

    --> ErrorCode=BadRequest

系统

  • .NET Framework 4.6.1
  • Windows 10 内部版本 17134
  • 服务区域 = "westeurope"

代码

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();
        }
    }
}

调试截图

enter image description here

最佳答案

Azure 似乎仅在包含语音标签时才接受 SSML。否则,您将收到 http-400 错误。

使用下面的代码,对 SpeakSsmlAsync 的调用成功运行:

text = @"<speak version='1.0' xmlns='https://www.w3.org/2001/10/synthesis' xml:lang='en-US'><voice name='en-US-ZiraRUS'>abracadabra</voice></speak>";
using (var result = await synthesizer.SpeakSsmlAsync(text))

搜索 Microsoft SSML 时要小心。有区别

https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-synthesis-markup

(这是针对 Azure 语音服务进行编程时需要的)和

https://learn.microsoft.com/en-us/cortana/skills/speech-synthesis-markup-language

关于c# - SpeakSsmlAsync 返回 BadRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56423958/

相关文章:

c# - 无法从远程机器连接

c# - 如何通过缓存键锁定?

c# - 如何对 Windows 窗体单选按钮进行分组?

Mac 上的 Python 文本转语音 丹麦语单词发音错误

google-chrome - 将 SSML 与 Web Speech API 结合使用的正确方法

c# - 在 C# 应用程序中运行 CPP 文件?

c# - 在 C# 中等待后台线程完成处理的最佳方法

c# - .NET CompactFramework TextBox.selectAll on gotFocus

c# - 修改字典值而不分配

clojure - Clojure 有哪些文本转语音和语音识别库可用?