tel42edgetts is an Asterisk AGI program designed to dynamically synthesize text-to-speech (TTS) using Microsoft Edge's high-quality neural voices.
- Microsoft Edge TTS API
- caching based on MD5 hashes of text + language + voice + format
- wav16 / wav / mp3 formats
- builtin mp3 to pcm convert
- IVR mode: user input can interrupt audio playback (single digit or digits ending with #)
Run the build target via Make:
make buildThis produces the statically linked executable binary tel42edgetts.
You can call the executable out of an Asterisk dialplan via AGI, or run it directly from the command line for testing:
tel42edgetts [OPTIONS] [TEXT]-lang: Language for TTS (default:en-US).-voice: Voice name (default:en-US-AvaMultilingualNeural).-format: Output audio format (mp3,wav,wav16) (default:wav16).-dir: Directory to store cached audio files (default:/tmp).-cache: Enable caching of audio files. Use-cache=falseto disable (default:true, env:TTS_CACHE).-ivr: Enable IVR mode - user input can interrupt playback (env:TTS_IVR).-ivr-mode: IVR input mode:single(single digit) orhash(digits ending with #) (env:TTS_IVR_MODE, default:single).-ivr-timeout: Timeout in milliseconds for waiting user input after playback completes (env:TTS_IVR_TIMEOUT, default:5000).-version: Print version and exit.
TTS_CACHE: Set tofalseor0to disable caching by default. Can be overridden by the-cachecommand-line flag.TTS_IVR: Set totrueor1to enable IVR mode by default.TTS_IVR_MODE: Set tosingleorhashto specify IVR input mode by default.TTS_IVR_TIMEOUT: Timeout in milliseconds for waiting user input after playback (default:5000).
You can override CLI flags by setting the following channel variables before calling the AGI:
TTS_TEXT: The text you want to synthesize.TTS_LANG: Language code (e.g.en-US).TTS_VOICE: Target voice (e.g.en-US-AvaMultilingualNeural).TTS_FORMAT: Target format (e.g.wav16).TTS_CACHE_DIR: Directory for cache (e.g./tmp).TTS_CACHE: Enable or disable caching (e.g.falseor0).TTS_IVR: Enable IVR mode (e.g.trueor1).TTS_IVR_MODE: IVR input mode (singleorhash).TTS_IVR_TIMEOUT: Timeout in milliseconds for waiting user input after playback (default:5000).
The script exports the outcome under the following Asterisk channel variables:
TTS_STATUS: Will be set toSUCCESSif the audio was downloaded/processed successfully, orERRORif the synthesis failed (e.g., missing text, network error).TTS_USERINPUT: Contains the user input received during IVR mode (empty string if no input).- In
singlemode: contains the single digit pressed (during or after playback) - In
hashmode: contains the digit string ending with#(or empty if timeout)
- In
...
same => n,Answer()
same => n,Set(TTS_TEXT=欢迎拨打智能语音服务,现在可以开始为您播放语音。)
same => n,Set(TTS_LANG=zh-CN)
same => n,Set(TTS_VOICE=Xiaoxiao)
same => n,Set(TTS_FORMAT=wav16)
same => n,Set(TTS_CACHE=true)
; Run the AGI script to synthesize and play the audio
same => n,AGI(tel42edgetts)
; Check the result
same => n,GotoIf($["${TTS_STATUS}"="SUCCESS"]?done:error)
; IVR Mode Example - single digit mode
same => n,Set(TTS_TEXT=Press 1 for sales, 2 for support.)
same => n,Set(TTS_IVR=true)
same => n,Set(TTS_IVR_MODE=single)
same => n,AGI(tel42edgetts)
same => n,Verbose(1,User pressed: ${TTS_USERINPUT})
; IVR Mode Example - hash mode
same => n,Set(TTS_TEXT=Please enter your extension number followed by hash.)
same => n,Set(TTS_IVR=true)
same => n,Set(TTS_IVR_MODE=hash)
same => n,AGI(tel42edgetts)
same => n,Verbose(1,User entered: ${TTS_USERINPUT})
; Fallback if TTS fails
same => n(error),Playback(vm-sorry)
same => n(done),Hangup()
...MIT