Last active
February 26, 2025 21:22
-
-
Save varnav/5ba27e02181e3354992e964bdaeeb432 to your computer and use it in GitHub Desktop.
Yandex SpechKit Asterisk Bash AGI curl REST API v3 speech synthesis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HASH=$(echo -n "$1" | sha256sum | awk '{print $1}') | |
if [ -f "/tmp/${HASH}.sln" ]; then | |
echo "EXEC PLAYBACK /tmp/${HASH}" | |
exit 0 | |
fi | |
cat << EOF > /tmp/${HASH}.json | |
{ | |
"text": "$1", | |
"hints": [ | |
{"voice": "lera"}, | |
{"speed": "1.1"}, | |
{"role": "friendly"}, | |
{"pitchShift": "-15"} | |
] | |
} | |
EOF | |
#cat /tmp/${TIMESTAMP}.json | |
cat /tmp/${HASH}.json | jq '.' | |
export FOLDER_ID=secret | |
export API_KEY=secret | |
curl -s -H "Authorization: Api-key $API_KEY" -H "x-folder-id: $FOLDER_ID" --data @/tmp/${HASH}.json https://tts.api.cloud.yandex.net:443/tts/v3/utteranceSynthesis | jq -r '.result.audioChunk.data' | while read chunk; do base64 -d <<< "$chunk" >> /tmp/${HASH}.wav; done | |
sox /tmp/${HASH}.wav --encoding ima-adpcm -c 1 -e signed-integer /tmp/${HASH}.sln | |
rm -f /tmp/${HASH}.wav /tmp/${HASH}.json | |
echo "EXEC PLAYBACK /tmp/${HASH}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment