Google tts api giving me blank mp3

我怕爱的太早我们不能终老 提交于 2019-12-23 03:42:30

问题


I'm trying to use google text-to-speech but the service not giving me. I'm using this url to get mp3 : http://translate.google.com/translate_tts?ie=utf-8&tl=en&q={$text}

Service return the error : our client does not have permission to get URL. How can I fix this ?


回答1:


Using cURL will avoid some checks:

<?php
    header("Content-Type: audio/mpeg");

    $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;
?>


来源:https://stackoverflow.com/questions/12669075/google-tts-api-giving-me-blank-mp3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!