Skip to content

Instantly share code, notes, and snippets.

@varnav
Last active February 26, 2025 21:22
Show Gist options
  • Save varnav/5ba27e02181e3354992e964bdaeeb432 to your computer and use it in GitHub Desktop.
Save varnav/5ba27e02181e3354992e964bdaeeb432 to your computer and use it in GitHub Desktop.
Yandex SpechKit Asterisk Bash AGI curl REST API v3 speech synthesis
#!/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