Skip to content

kywalda/watalk.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

#!/bin/sh
##############################################################
#             watalk.sh                                      #
# Bash script to generate and keep TTS soundfiles            #
# to be used by Asterisk extensions                          #
# generated by IBM Watson Text to Speach API                 #
#                                                            #
# from Arne Groh 07/2022                                     #
#                                                            #
# sample:                                                    #
# exten => 1234,1,Answer()                                   #
#  same => n,System(/usr/local/bin/watalk.sh "Guten Morgen.")#
#  same => n,Playback(/tmp/sprech)                           #
#  same => n,Hangup()                                        #
#                                                            #
# installation:                                              #
# format_mp3.so  has to be loaded in Asterisk                #
# put this script in your /usr/local/bin/        directory   #
# make it executable:                                        #
# sudo chmod +x /usr/local/bin/watalk.sh                     #
# give to Asterisk:                                          #
# sudo chown asterisk:asterisk /usr/local/bin/watalk.sh      #
#                                                            #
##############################################################

# Set your IBM Cloud credentials
apikey=abcdefghabcdefg_123456789098765432123456-a_B
url=https://api.eu-de.text-to-speech.watson.cloud.ibm.com/instances/98765433-abcd-efab-abcd-1234567890ab

# Set the voice
voice=de-DE_BirgitV3Voice
# voice=de-DE_DieterV3Voice

# Set tuning
rate="-10%"
pitch="150Hz"

# Soundfile to be played by Asterisk exten
wavfile=/tmp/sprech.mp3

# Folder where generated sound files will be stored
storedir=/var/lib/asterisk/sounds/tts

text=$1 # First argument
name=$(echo $text|md5sum|cut -d" " -f1).mp3
storefile=$storedir/$name
apikey=apikey:$apikey
url=$url/v1/synthesize?voice=$voice
rate=\'$rate\'
pitch=\'$pitch\'

if [ ! -f $storefile ]
then
        curl -X POST -u ${apikey} \
        --header "Content-Type: application/json" \
        --header "Accept: audio/mp3" \
        --data "{\"text\":\"<prosody rate=${rate} pitch=${pitch}>${text}</prosody>\"}" \
        --output ${storefile} \
        "${url}"
fi
rm -f $wavfile
cp $storefile $wavfile
exit

About

Bash script to generate and keep TTS soundfiles to be used by Asterisk extensions generated by IBM Watson Text to Speach API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages