Was this page helpful?

多國 TTS - Google TTS

    Google TTS - 這是 Google 提供的 TTS 線上服務,可轉換各國語言。轉換的語音品質可以前往這個網站作測試,http://translate.google.com/?hl=en

    透過 AGI:googletts.agi 可以將此服務整合到 Asterisk。

    更新於 2017/12/3:
    每次傳送限制 5000 字元以內,詳細參閱 https://cloud.google.com/translate/faq#technical

    更新於 2017/7/21:
    Asterisk 11.12(Incredible PBX 11.10) 使用中文正常。



    • Perl                   -The Perl Programming Language
    • perl-libwww     -The World-Wide Web library for Perl
      #apt-get install libwww-perl
    • sox                     -Sound eXchange, sound processing program
    • mpg123             -MPEG Audio Player and decoder
      #apt-get install mpg123
    • format_sln          -Raw slinear module for asterisk
    • Internet access   -in order to contact google and get the voice data.


    下載 AGI:http://zaf.github.com/asterisk-googletts/


    exten => s,1,Answer
    exten => s,n,Wait(2)
    ;exten => s,n(start),Flite(After the beep. Press the number of the radio channel you wish to listen to. Or 9 for a list of channels.)
    exten => s,n(start),AGI(googletts.agi,"歡迎使用,開放軟體實驗室,網路電話平台。",zh-TW,any)
    exten => s,n,AGI(googletts.agi,"目前您正在收聽網路電台,請在嗶聲後,輸入您想收聽的電台編號",zh-TW,any)
    exten => s,n,AGI(googletts.agi,"或按 9 查詢電台的編號",zh-TW,any)
    exten => s,n,Read(MusicCode,beep,1)
    exten => s,n,GotoIf($["${MusicCode}" = ""]?end)
    exten => s,n,GotoIf($["${MusicCode}" != "9" & ${MusicCode} > 4]?M9:M${MusicCode})
    exten => s,n(M1),MusicOnHold(radio-1)
    exten => s,n(M2),MusicOnHold(radio-2)
    exten => s,n(M3),MusicOnHold(radio-3)
    exten => s,n(M4),MusicOnHold(radio-4)
    ;exten => s,n(M9),Flite(Press 1 for Classical Music. Press 2 for Live Information. Press 3 for News Radio. Press 4 for Taiwan Voice Radio. Press 9 to hear this list again.)
    exten => s,n(M9),AGI(googletts.agi,"古典音樂,請按 1,生活資訊,請按 2",zh-TW,any)
    exten => s,n,AGI(googletts.agi,"新聞時事,請按 3,綜合資訊,請按 4",zh-TW,any)
    exten => s,n,GoTo(start)
    ;exten => s,n(end),Flite("Thank you for calling us. Goodbye")
    exten => s,n(end),AGI(googletts.agi,"謝謝您的來電",zh-TW,any)
    exten => s,n,Hangup



       $string = "Parameter string missing. Please solve this issue.";
       $string = trim($argv[1]);
       $string = "Parameter language missing. Please solve this issue.";
       $lang = 'en';
        $lang = trim($argv[2]);
    $ttsFile = tts($string,$lang);
    return $ttsFile;
    function tts($string, $lang){
       $string = urlencode($string);
            if(strlen($string > 100)){
                echo("Google limit text2speech to 100 caracters. Please cut your string ...");
                return false;
       $id = uniqid("ivr_");
       exec('curl -A "Mozilla" "http://translate.google.com/translate_tts?ie=UTF-8&tl='.$lang.'&q='.$string.'" > /tmp/'.$id.'.mp3');
       exec('/usr/bin/mpg123 -w /tmp/'.$id.'.wav /tmp/'.$id.'.mp3');
       exec('/usr/bin/sox /tmp/'.$id.'.wav -t raw -r 8000 -s -c 1 /tmp/'.$id.'.sln');


    exten => 1000,1,Answer()
    same => n, Set(SOUNDFILE=${SHELL(/usr/bin/php /var/lib/asterisk/agi-bin/googleTTS.php ${CALLERID(num)})})
    same => n, Playback(${SOUNDFILE})
    same => n,Hangup()
    Was this page helpful?
    標籤 (Edit tags)
    • No tags
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core