Google tts api 给我空白的 mp3 [英] Google tts api giving me blank mp3

查看:45
本文介绍了Google tts api 给我空白的 mp3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 google 文本转语音,但该服务没有给我.我正在使用这个 url 来获取 mp3 :http://translate.google.com/translate_tts?ie=utf-8&tl=en&q={$text}

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}

服务返回错误:我们的客户端没有获取 URL 的权限.我该如何解决这个问题?

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

推荐答案

使用 cURL 将避免一些检查:

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

这篇关于Google tts api 给我空白的 mp3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆