Cognitive Services - Text to speech REST API - not all words are converted when selecting ogg as output format

2024-08-08T07:18:46.1233333+00:00

calling text to speech API selecting ogg-16khz-16bit-mono-opus not synthesizing all the words.

For Example:

Text: "First Floor"

It is converting only first word, and the word Floor is not getting synthesized.

Azure Speech in Foundry Tools
Microsoft Teams | Microsoft Teams for business | Other
Developer technologies | ASP.NET Core | Other
0 comments No comments

Answer accepted by question author
Anonymous
2024-08-08T10:36:05.23+00:00

Hi @Chirravuri Venkata, Bharani Chakravarthy,

I create a speech service and using below code, it works fine. And I also verified the generated ogg file, it's correct.

User's image

Test Code

// See https://aka.ms/new-console-template for more information
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
    private static readonly string apiKey = "Your_Api_Key";
    private static readonly string endpoint = "https://eastasia.tts.speech.microsoft.com/cognitiveservices/v1";
    //https://%SPEECH_REGION%.tts.speech.microsoft.com/cognitiveservices/v1
    static async Task Main(string[] args)
    {
        string text = "First Floor";
        string voice = "en-US-JennyNeural";
        string audioFormat = "ogg-16khz-16bit-mono-opus";
        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", apiKey);
            var request = new HttpRequestMessage(HttpMethod.Post, endpoint);
            request.Content = new StringContent(GenerateSsml(text, voice), Encoding.UTF8, "application/ssml+xml");
            request.Headers.Add("X-Microsoft-OutputFormat", audioFormat);
            request.Headers.Add("User-Agent", "ConsoleApp");
            var response = await client.SendAsync(request);
            response.EnsureSuccessStatusCode();
            using (Stream responseStream = await response.Content.ReadAsStreamAsync())
            using (FileStream fileStream = new FileStream("output.ogg", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                await responseStream.CopyToAsync(fileStream);
                Console.WriteLine("Audio file saved successfully.");
            }
        }
    }
    static string GenerateSsml(string text, string voice)
    {
        return $@"
        <speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>
            <voice name='{voice}'>{text}</voice>
        </speak>";
    }
}

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best Regards

Jason

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.