Google TTS API:使用PHP编码GET请求 [英] Google TTS API: Encoding GET request with PHP

查看:115
本文介绍了Google TTS API:使用PHP编码GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

--- SOLVED ---

--- SOLVED ---

解决问题。解决方案很简单:

Problem solved. Solution is simple:

file_get_contents("http://translate.google.com/translate_tts?tl=de&q=".urlencode($str)."&ie=UTF-8")

从搜索引擎:确保将文件字符集设置为UTF-8,将ie = UTF-8参数包含到URL中,对您的字符串进行urlencode。一切都应该是好的。

To those coming here from search engine: Make sure you set the file charset to UTF-8, include the ie=UTF-8 parameter into the URL, urlencode your string. Everything should be fine then.

ORIGINAL POST WAS:

ORIGINAL POST WAS:

我有一个问题,使PHP发送正确编码的GET请求给Google TTS API。

I have a problem with making PHP send a correctly encoded GET request to the Google TTS API.

$str='This is a German string which contains crazy Umlaute like ä (like in Häuser) or ü (like in Übermensch). Sehr deutsch halt.';
file_get_contents("http://translate.google.com/translate_tts?tl=de&q=".$str."&ie=UTF-8");

所有包含的PHP文件都以UTF-8编码(无字节顺序标记)。 Google TTS返回给我的是一个MP3文件,它表示Umlaute不像Übermensch,而是像A〜1 / 4bermensch一样。这个问题与客户端无关。

All included PHP files are encoded in UTF-8 (no byte order marks). What Google TTS returns to me is an MP3 file which spells the "Umlaute" not like Übermensch, but like A~1/4bermensch. This problem has nothing to do with the client side.

我认为Google正在期待一个ASCII字符串,这可能是我的问题?当我手动将GET行输入到浏览器中时,它会正确地显示所有内容。另见:

I think Google is expecting an ASCII string, this might be my problem? When I type the GET line into my browser manually however, it spells everything correctly. See also:

stackoverflow - 用于阿拉伯语,中文和希腊语的Google TTS API

感谢您的帮助!!

推荐答案

您必须将编码网址Parameter& ie = utf-8和python文件本身的编码设置为:#coding:utf-8,并确保安全。 py文件与utf-8编码(不是iso-8859-1)。

You have to set the encoding URL Parameter &ie=utf-8 and the encoding of the python file itself to: #coding: utf-8 and be sure to safe the .py file with utf-8 encoding (not iso-8859-1).

这篇关于Google TTS API:使用PHP编码GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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