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

Fortressing the digital frontier: A comprehensive look at IBM Cloud network security services

6 min read - The cloud revolution has fundamentally transformed how businesses operate. Its superior scalability, agility and cost-effectiveness have made it the go-to platform for organizations of all sizes. However, this shift to the cloud has introduced a new landscape of ever-evolving security threats. Data breaches and cyberattacks continue to hit organizations, making robust cloud network security an absolute necessity. IBM®, a titan in the tech industry, recognizes this critical need, provides a comprehensive suite of tools and offers unmatched expertise to fortify…

How well do you know your hypervisor and firmware?

6 min read - IBM Cloud® Virtual Private Cloud (VPC) is designed for secured cloud computing, and several features of our platform planning, development and operations help ensure that design. However, because security in the cloud is typically a shared responsibility between the cloud service provider and the customer, it’s essential for you to fully understand the layers of security that your workloads run on here with us. That’s why here, we detail a few key security components of IBM Cloud VPC that aim…

New IBM study: How business leaders can harness the power of gen AI to drive sustainable IT transformation

3 min read - As organizations strive to balance productivity, innovation and environmental responsibility, the need for sustainable IT practices is even more pressing. A new global study from the IBM Institute for Business Value reveals that emerging technologies, particularly generative AI, can play a pivotal role in advancing sustainable IT initiatives. However, successful transformation of IT systems demands a strategic and enterprise-wide approach to sustainability. The power of generative AI in sustainable IT Generative AI is creating new opportunities to transform IT operations…

IBM Newsletters

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