问题
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