Bash Script - Text to Speech

Use the Bash script below to speak some text. I like to use this for alarms and completion messages on long running jobs. For example I burn Raspberry Pi thin client images at work which take over 30 minutes to complete.

You’ll need to obtain a key to use IBM Watson Text to Speech API.

At the bottom of the page is an example audio message uploaded to YouTube.

#!/bin/bash
#
# Speak text
#
temporaryFile=$(mktemp)
/usr/bin/curl  -v -X POST -u YourApiKeyGoesHere:YourPasswordGoesHere \
  --header "Content-Type: application/json" \
  --header "Accept: audio/wav" \
  --data '{"text":"'"$1"'"}' \
  --output "$temporaryFile" \
  "https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize"
/usr/bin/mplayer "$temporaryFile"

Example

~/speak.sh "Congratulations! The Raspberry Pi thin client image is ready. It took 41 minutes to burn."