【问题标题】:SpeakSsmlAsync returns BadRequestSpeakSsmlAsync 返回 BadRequest
【发布时间】: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?

重现步骤:

  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. SpeakTextAsync 替换为SpeakSsmlAsync

  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 框架 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


    【解决方案1】:

    Azure 似乎仅在包含语音标签时才接受 SSML。否则你会得到 http-400-error。

    使用下面的代码调用 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://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-synthesis-markup

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

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

    【讨论】:

    • 我的理解是语音是可选的。所以问题可能是你为什么会收到 400 错误?会不会是语音服务正在寻找未安装的默认语音?我会将其标记为语音服务文档中的缺陷和/或使用反馈进行报告。
    • @Micromuncher 我刚刚在 MSDN 论坛上得到了确认该行为的答案。他们会检查是否可以修复它social.msdn.microsoft.com/Forums/en-US/…
    • 您真的能掌握返回并自动播放的音频文件吗?由于每个新请求都会从服务器获取一个新的音频文件(即使文本没有更改),因此将音频文件隐藏起来以供以后使用并从该“缓存”中播放它会很方便。有人吗?
    • @mramosch - 是的,当然,这就是你通常会做的事情。如果它对您不起作用,也许发布相应的问题是正确的方法。
    • 我想我最好把问题放在这里,人们参与其中似乎有必要的知识来帮助我。通常当我发布一些新问题时,我根本没有得到任何回应......
    【解决方案2】:

    是的,Azure TTS 服务仅接受带有语音标签的 SSML。

    原因是语音太多,所以最好明确指定使用哪个语音。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      • 2015-10-10
      • 2022-08-17
      • 2021-08-29
      相关资源
      最近更新 更多