简体   繁体   中英

Azure TTS neural voice audio file is created abnormally in 1 byte size

Azure TTS standard voice audio files are generated normally. However, for neural voice, the audio file is generated abnormally with the size of 1 byte. The code is below.

C# code

public static async Task SynthesizeAudioAsync()
{
   var config = SpeechConfig.FromSubscription("xxxxxxxxxKey", "xxxxxxxRegion");
   using var synthesizer = new SpeechSynthesizer(config, null);

   var ssml = File.ReadAllText("C:/ssml.xml");
   var result = await synthesizer.SpeakSsmlAsync(ssml);

​   using var stream = AudioDataStream.FromResult(result);
   await stream.SaveToWaveFileAsync("C:/file.wav");
}

ssml.xml - The file below, set to standard voice, works fine.

<speak version="1.0" xmlns="https://www.w3.org/2001/10/synthesis" xml:lang="en-US">
  <voice name="en-GB-George-Apollo">
    When you're on the motorway, it's a good idea to use a sat-nav.
  </voice>
</speak>

ssml.xml - However, the following file set for neural voice does not work, and an empty sound source file is created.

<speak version="1.0" xmlns="https://www.w3.org/2001/10/synthesis" xml:lang="en-US">
  <voice name="en-US-AriaNeural">
    When you're on the motorway, it's a good idea to use a sat-nav.
  </voice>
</speak>

Looking at the behavior you have described due to some issues, the Speech service has returned no audio bytes.

I have checked the SSML file at my end it works completely fine ie there is no issues with the SSML.

As a next step to the solution, I would recommend you to add error handling code to give better picture of the error and take the action accordingly:

    var config = SpeechConfig.FromSubscription("xxxxxxxxxKey", "xxxxxxxRegion");
    using var synthesizer = new SpeechSynthesizer(config, null);

    var ssml = File.ReadAllText("C:/ssml.xml");
    var result = await synthesizer.SpeakSsmlAsync(ssml);
    if (result.Reason == ResultReason.Canceled)
    {
        var cancellation = SpeechSynthesisCancellationDetails.FromResult(result);
        Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
        if (result.Reason == ResultReason.SynthesizingAudioCompleted)
        {
        Console.WriteLine ("No error ")
         using var stream = AudioDataStream.FromResult(result);
            await stream.SaveToWaveFileAsync("C:/file.wav");

        }

        else if (cancellation.Reason == CancellationReason.Error)
        {
            {
                Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                Console.WriteLine($"CANCELED: ErrorDetails=[{cancellation.ErrorDetails}]");
                
            }
        }

The above piece of modification will provide friendly error message on the console app.

Note: If you are not using the console app, you will have modify the code.

Sample output:

This is just a sample output. the error you might see would be different. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM