Getting Error when using TTS service with text containing special character '<'

Nokhalal Mahato 0 Reputation points
2025-01-24T10:44:48.3833333+00:00

I am using microsoft-cognitiveservices-speech-sdk for text to speech. Before sending the text to SpeechSynthesizer i am creating a ssml and then passing the smml to speakSsmlAsync method.

I am getting a issue in this process , if my text contain special character '<' then i am getting error Invalid tag name '=' found in line 3 position 41. websocket error code: 1007
where my text is n<=5 here tag name is any character after < symbol.

My ssml code is -

<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>
<voice name='en-IN-AaravNeural'>
<prosody rate='-10%'>${text}</prosody>
</voice>
</speak>
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,880 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Manas Mohanty (Quadrant Resource LLC) 95 Reputation points Microsoft Vendor
    2025-01-24T12:14:45.69+00:00

    Hi Nokhalal Mahato!

    Welcome to Microsoft Q&A Forum, thank you for posting your query here.

    To use the characters &, <, and > within the SSML element's value or text, you must use the entity format.

    "

    > instead of >

    < instead of <

    "

    n&lt;=5 # for text "n<=5"
    
    <speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>
      <voice name='en-IN-AaravNeural'>
        <prosody rate='-10%'>n&lt;=5</prosody>
      </voice>
    </speak>
    

    Kindly refer below document

    https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-structure?form=MG0AV3#special-characters

    Thank you.


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.