【问题标题】:jquery for google tts no voicejquery for google tts 没有声音
【发布时间】:2013-12-04 07:04:44
【问题描述】:

当我使用此代码让 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. 在浏览器中火狐更好但有上述问题
  2. 在 IE 中是音频错误:不支持文件类型...
  3. 在 Chorme 中没有任何动作,甚至 //translate.google.com/translate_tts?tl=en&q=dog 没有声音

我想知道如何修复让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;
    });

【问题讨论】:

    标签: javascript jquery audio


    【解决方案1】:

    你为什么不用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;
    

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

    【讨论】:

    • 虽然这可能有效,但问题并未提及使用 PHP。 OP 正在寻求在 jQuery 中实现这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多