Created
January 21, 2025 21:22
-
-
Save varnav/d169a010f139c82f3bca3eb78d852ca8 to your computer and use it in GitHub Desktop.
Asterisk Yandex TTS
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
[yasay] | |
; Configuration variables | |
exten => s,1,Set(SPEAKER=jane) | |
same => n,Set(EMOTION=neutral) | |
same => n,Set(API_KEY=useyourown) | |
same => n,Set(CACHE_DIR=/tmp) | |
; Generate MD5 hash of the text | |
same => n,Set(MD5_HASH=${MD5("${ARG1}")}) | |
same => n,Set(FILE_PATH=${CACHE_DIR}/${MD5_HASH}) | |
; Check if cached file exists | |
same => n,ExecIf($[${STAT(f,${FILE_PATH}.sln)} = 0]?GoTo(generate,1)) | |
same => n,Playback(${FILE_PATH}) | |
same => n,Return | |
; Generate new audio if not cached | |
exten => generate,1,Set(URL=https://tts.voicetech.yandex.net/generate?lang=ru-RU&speaker=${SPEAKER}&emotion=${EMOTION}&key=${API_KEY}&text=${URIENCODE(${ARG1})}) | |
; Download MP3 | |
same => n,System(curl '${URL}' -o ${FILE_PATH}.ogg) | |
; Convert to required format | |
same => n,System(ffmpeg -i ${FILE_PATH}.ogg -ar 8000 -ac 1 -acodec pcm_s16le -f s16le ${FILE_PATH}.sln) | |
; Play the generated audio | |
same => n,Playback(${FILE_PATH}) | |
same => n,Return | |
[example] | |
exten => s,1,Answer() | |
same => n,GoSub(yasay,${EXTEN},1("Бдыжь")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment