Skip to content

Instantly share code, notes, and snippets.

@BrettSheleski
Last active January 3, 2019 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrettSheleski/a54bba8bca02bab0d7c023ff96575c12 to your computer and use it in GitHub Desktop.
Save BrettSheleski/a54bba8bca02bab0d7c023ff96575c12 to your computer and use it in GitHub Desktop.
Script to convert text to speech using naturalreaders.com
#!/bin/bash
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
}
TXT=$(cat)
JSON=$(echo "t=$TXT" | jo)
TXTENCODED=$(urlencode "$TXT")
curl -s "https://kfiuqykx63.execute-api.us-east-1.amazonaws.com/Dev/tts?r=12&s=0&l=0&v=aca&t=${TXTENCODED}" \
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:64.0) Gecko/20100101 Firefox/64.0' \
-H 'Accept: */*' \
-H 'Accept-Language: en-US,en;q=0.5' \
--compressed \
-H 'Referer: https://www.naturalreaders.com/online/' \
-H 'content-type: application/x-www-form-urlencoded' \
-H 'origin: https://www.naturalreaders.com' \
-H 'Connection: keep-alive' \
--data "$JSON" \
--output -
@BrettSheleski
Copy link
Author

Example usage:

echo The cow says moo | ./tts.sh > moo.mp3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment