Google tts api 给我空白的 mp3

编程入门 行业动态 更新时间:2024-10-14 00:30:30
本文介绍了Google tts api 给我空白的 mp3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试使用 google 文本转语音,但该服务没有给我.我正在使用这个 url 来获取 mp3 :http://translate.google/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/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/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 19:35:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1398916.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:给我   空白   tts   Google   api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!