Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpeakSsmlAsync returns BadRequest

When calling SpeakSsmlAsync (Microsoft Speech SDK), the following error message is returned:

> CANCELED: Reason=Error
> CANCELED: ErrorCode=BadRequest 
> CANCELED: ErrorDetails=[HTTPAPI result code = HTTPAPI_OK. HTTP status code=400.] 
> CANCELED: Did you update the subscription info?

Steps to reproduce:

  1. Download Quickstart sample from https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/text-to-speech/csharp-dotnet-windows

  2. Replace Subscription ID and region with own values, set active configuration as described in documentation, clean and rebuild project

  3. Start program and enter some text like "abracadabra"

    --> Works fine (uses SpeakTextAsync)

  4. Replace SpeakTextAsync with SpeakSsmlAsync

  5. Start programm and enter some text

    --> ErrorCode=BadRequest

  6. Retry with proper SSML code like <speak version="1.0" xmlns="https://www.w3.org/2001/10/synthesis" xml:lang="en-US">abracadabra</speak>"

    --> ErrorCode=BadRequest

System

  • .NET Framework 4.6.1
  • Windows 10 Build 17134
  • Service Region = "westeurope"

Code

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

Debug Screenshot

enter image description here

like image 649
Frank im Wald Avatar asked Sep 18 '26 15:09

Frank im Wald


1 Answers

Azure seems to accept SSML only when a voice-tag is included. Otherwise you'll get the http-400-error.

With the code below the call to SpeakSsmlAsync works successfully:

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))

Watch out when searching for Microsoft SSML. There is a difference between

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

(which is what you want when programming against Azure Speech services) and

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

like image 59
Frank im Wald Avatar answered Sep 20 '26 07:09

Frank im Wald