How do I pause for x number of seconds with Microsoft.CognitiveServices Text to Speech?

Data Juggler 181 Reputation points
2023-11-10T22:12:51.7233333+00:00

I learned how to use SSML, which is a little clunky considering I have to read a text file, and do text replacements to set different attributes.

What I would like to do, is in certain places, allow the script to be spoken to have a command such as [Pause5] to pause for 5 seconds. Sometimes a break between topics it is more natural sounding to have a pause. I tried adding multiple commas, and this doesn't seem to work.

Is there a way I can instruct the text to speech to pause for a certain amount of time?

Here is my SSML Template file that I use to make replacements.

If I need to include something in the [TextToSpeak] braces I can do that.

Thank you

<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="[Locale]">
    <voice name="[VoiceName]">
        <mstts:express-as role="[Role]" style="[Emotion]" styledegree="[Degree]">
            [TextToSpeak]
        </mstts:express-as>
    </voice>
</speak>
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,487 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. VasaviLankipalle-MSFT 15,511 Reputation points
    2023-11-10T22:46:04.36+00:00

    Hello @Data Juggler , Thanks for using Microsoft Q&A Platform.

    I'm glad that you were able to resolve your issue, posting solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue: To pause for certain number of seconds with Microsoft.CognitiveServices Text to Speech?

    Solution:

    Yes, you can use the break element in SSML to pause for a certain amount of time. To specify the duration of the pause, you can use the time or strength attribute of the break element: https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-structure#add-a-break

    Here is the sample code:

    <speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">
        <voice name="en-US-JennyNeural">
            Welcome <break /> to text to speech.
            Welcome <break strength="medium" /> to text to speech.
            Welcome <break time="750ms" /> to text to speech.
        </voice>
    </speak>
    

    If you have any other questions or are still running into more issues, please let me know.

    Thank you again for your time and patience throughout this issue.

    Regards,
    Vasavi

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    0 comments No comments