jquery for google tts no voice

时间:2013-12-04 07:04:44

标签: javascript jquery audio

当我使用此代码时,让google_tts说出单词语音,代码没问题,但有问题。单词语音必须首先监听http://translate.google.com/translate_tts?tl=en&q=dog(word)然后运行此代码,结果正常,但是当我不首先听http://translate.google.com/translate_tts?tl=en&q=dog(word)代码时,代码不能说出单词。我参考Google Translate TTS problem,我想知道真正的问题以及如何解决它?

  1. 在浏览器中,Firefox更好但有上述问题
  2. 在IE中是音频错误:不支持文件类型...
  3. 在Chorme中没有任何操作,甚至//translate.google.com/translate_tts?tl=en&q=dog都没有发言权
  4. 我想知道如何修复让IE和Firefox浏览器运行成功,非常感谢

    HTML

    <form id="say-form">
            <button id="say-button">Say!</button>
            <audio id="audio" preload controls>
                <source id="s1" />
            </audio>
       </form>
    

    JQuery的

     $('#say-form').submit(function(){
            var ar = new Array("dog","egg","what","big")
            var i=0,file = $("#audio")
            console.log(ar[0])
            $("#s1").attr("src", "http://translate.google.com/translate_tts?tl=en&q="+ar[0]).detach().appendTo("#audio");
            file[0].load();
            file[0].play();
            i++;
            // when it play end, play next word until ar array it's finish
            file.on( "ended", function(){
                if(i!=ar.length)
                {
                    $("#s1").attr("src", "http://translate.google.com/translate_tts?tl=en&q="+ar[i]).detach().appendTo("#audio");
                    $(this)[0].load();
                    $(this)[0].play();
                    i++;
                }
            });
            return false;
        });
    

1 个答案:

答案 0 :(得分:0)

你为什么不用Php?

$text = urlencode('my text');
$url = "http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=".$text;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$return = curl_exec($ch);
curl_close($ch);

echo $return;

&GT?; 像这样Google tts api giving me blank mp3 或者http://ctrlq.org/code/19147-text-to-speech-php