WordBoundary event not called when using Neural Text to speech container

Tommy Andreasen 20 Reputation points
2024-03-11T11:55:39.81+00:00

Hi,

I'm trying to use the Neural Text To Speech containers from a C# project.

I have the container running locally, and I'm able to get text read out loud via the container using Microsoft.CognitiveServices.Speech v1.36.0.

My issue is that I need the WordBoundary event to be called back. But when using the local container this event is not invoked at all.

If I switch to use my Azure subscription ( Speech.Config.FromSubsribtion(...) )it works as expected.

My sample code for demonstrating the issue

async static Task Main(string[] args)
{
    var speechConfig = SpeechConfig.FromHost(new Uri("http://localhost:5000"));
    // The language of the voice that speaks.
    speechConfig.SpeechSynthesisVoiceName = "da-DK-JeppeNeural";
    using (var speechSynthesizer = new SpeechSynthesizer(speechConfig))
    {
        speechSynthesizer.SynthesisStarted += (s, e) =>
        {
            Console.WriteLine("Synthesis started.");
        };
        speechSynthesizer.Synthesizing += (s, e) =>
        {
            Console.WriteLine($"Synthesizing, received an audio chunk of {e.Result.AudioData.Length} bytes.");
        };
        speechSynthesizer.WordBoundary += (s, e) =>
        {
            Console.Write($"Word \"{e.Text}\" | ");
            Console.Write($"Text offset {e.TextOffset} | ");
            Console.WriteLine($"Audio offset {(e.AudioOffset + 5000) / 10000}ms");
        };
        // Get text from the console and synthesize to the default speaker.
        Console.WriteLine("Enter some text that you want to speak >");
        string text = Console.ReadLine();
        var speechSynthesisResult = await speechSynthesizer.SpeakTextAsync(text);        
    }
    Console.WriteLine("Press any key to exit...");
    Console.ReadKey();
}
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,602 questions
{count} votes

Accepted answer
  1. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2024-03-22T05:18:44.24+00:00

    @Tommy Andreasen Apologies for the late reply. I appreciate your patience on this.

    Please note, tts container does support word-boundary. If you want to use this feature, you must switch to websocket protocol, just like below: 

    var speechConfig = SpeechConfig.FromHost(new Uri("ws://localhost:5000"));

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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