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:
Download Quickstart sample from https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/text-to-speech/csharp-dotnet-windows
Replace Subscription ID and region with own values, set active configuration as described in documentation, clean and rebuild project
Start program and enter some text like "abracadabra"
--> Works fine (uses SpeakTextAsync)
Replace SpeakTextAsync with SpeakSsmlAsync
Start programm and enter some text
--> ErrorCode=BadRequest
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
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

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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With