Learn how easy it is to control the speaking rate of the text using the <prosody> element in a cURL command.
A developer recently had a query that I was trying to answer: How do I adjust the speaking rate in IBM Watson Text to Speech using cURL POST?
While investigating, I came across the terms speaking rate and SSML. Before posting the answer to the query, let’s get familiar with the terms first.
What are speaking rate and SSML?
Speaking rate is often expressed in words per minute (wpm). To calculate this value, you’ll need to record yourself talking for a few minutes and then add up the number of words in your speech. Divide the total number of words by the number of minutes your speech took.
Speaking rate (wpm) = total words/number of minutes
The Speech Synthesis Markup Language (SSML) is an XML-based markup language that provides annotations of text for speech-synthesis applications. It is a recommendation of the W3C Voice-Browser Working Group that has been adopted as the standard markup language for speech synthesis by the VoiceXML 2.0 specification. SSML provides developers of speech applications with a standard way to control aspects of the synthesis process by enabling them to specify pronunciation, volume, pitch, speed, and other attributes via markup. For a complete introduction to SSML, refer to the IBM Cloud documentation.
Copy the credentials to authenticate to your service instance:
From the IBM Cloud Resource list, click on your Text to Speech service instance to go to the Text to Speech service dashboard page
On the Manage page, click Show Credentials to view your credentials
Copy the API Key and URL values and replace the placeholders {API_KEY} and {URL} with the respective values in the next section
Code snippets
Here’s a working example with the POST call on Linux or macOS:
curl -X POST -u "apikey:{API_KEY}"\ --header "Accept: audio/wav"\ --header "Content-Type: application/json"\ --data '{"text": "<p><s><prosody rate=\"+50%\">This is the first sentence of the paragraph.</prosody></s><s>Here is another sentence.</s><s>Finally, this is the last sentence.</s></p>"}'\ --output result.wav \ "{URL}/v1/synthesize"-v
Scroll to view full table
On a Windows command prompt, create a JSON file input.json with the following command:
echo { "text": "<p><s><prosody rate='+50%'>This is the first sentence of the paragraph.</prosody></s><s>Here is another sentence.</s><s>Finally, this is the last sentence.</s></p>"} > input.json
Build a Slackbot to create and search Db2 database entries for events and conferences.
Here are some useful links I followed to create the above code sample that will help you in understanding the SSML attributes. Also, check out the limitations of <prosody> in the links below.