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.

Before you begin

  • Create an instance of the service: 
    • Go to the Text to Speech page in the IBM Cloud Catalog
    • Sign up for a free IBM Cloud account or log in
    • Click Create
  • 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 

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 

Then, cURL to see result.wav file:

curl -X POST -u "apikey:{API_KEY}" ^
--header "Accept: audio/wav" ^
--header "Content-Type: application/json" ^
--data @input.json ^
--output result.wav ^
"{URL}/v1/synthesize" -v

Learn more

Learn how easy it is to quickly create a voice-enabled Android-native chatbot with the watsonx Assistant, Watson Text to Speech, and Watson Speech to Text services on IBM Cloud.

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.

Was this article helpful?
YesNo

More from Cloud

IBM + AWS: Transforming Software Development Lifecycle (SDLC) with generative AI

7 min read - Generative AI is not only changing the way applications are built, but the way they are envisioned, designed, tested, documented, and deployed. It’s also revolutionizing the software development lifecycle (SDLC). IBM and AWS are infusing Amazon Bedrock generative AI capabilities into the IBM® SDLC solution to drive increased efficiency, speed, quality and value in every application lifecycle consistently and at scale. And The evolution of the SDLC landscape The software development lifecycle has undergone several silent revolutions in recent decades.…

How digital solutions increase efficiency in warehouse management

3 min read - In the evolving landscape of modern business, the significance of robust operational and maintenance systems cannot be overstated. Efficient warehouse management helps businesses to operate seamlessly, ensure precision and drive productivity to new heights. In our increasingly digital world, bar coding stands out as a cornerstone technology, revolutionizing warehouses by enabling meticulous data tracking and streamlined workflows. With this knowledge, A3J Group is focused on using IBM® Maximo® Application Suite and the Red Hat® Marketplace to help bring inventory solutions…

How fintechs are helping banks accelerate innovation while navigating global regulations

4 min read - Financial institutions are partnering with technology firms—from cloud providers to fintechs—to adopt innovations that help them stay competitive, remain agile and improve the customer experience. However, the biggest hurdle to adopting new technologies is security and regulatory compliance. While third and fourth parties have the potential to introduce risk, they can also be the solution. As enterprises undergo their modernization journeys, fintechs are redefining digital transformation in ways that have never been seen before. This includes using hybrid cloud and…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters