【问题标题】:iPhone - Google Text-To-Speech special character URLiPhone - Google 文字转语音特殊字符 URL
【发布时间】:2011-01-08 07:15:17
【问题描述】:

我正在使用 iPhone 应用程序,我需要集成 Google Text-To-Speech (Google TTS)。

它仅适用于英文字母表中的字符。尝试使用 Ᾰ、Д、И 等特殊字符形成链接 (linkTTS) 时,它不再起作用。 代码如下所示:

NSString *queryTTS = [[NSString alloc] init]; //text to be read
queryTTS = [query stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSString *linkTTS = [NSString stringWithFormat:@"http://translate.google.com/translate_tts?tl=en&q=%@",queryTTS];

NSData *dataTTS = [NSData dataWithContentsOfURL:[NSURL URLWithString:linkTTS]];

ttsPlayer = [[AVAudioPlayer alloc] initWithData:dataTTS error:nil]; 
[ttsPlayer play];

我尝试使用 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding 但这不起作用,因为 Google TTS 无法识别这种类型的 URL 编码。

【问题讨论】:

    标签: iphone unicode text-to-speech google-text-to-speech


    【解决方案1】:

    我在使用 Android 应用程序时遇到了同样的问题。我尝试了许多编码类型,但没有奏效。 最终解决问题的方法是将 GET 请求的“User-Agent”属性指定为“Mozilla/5.0”。哦,我发现最适合的编码类型是 UTF-8。它允许识别大多数特殊字符,实际上是谷歌翻译支持的任何字符。
    希望这会有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 2012-06-02
      • 2023-03-03
      • 2014-02-28
      • 1970-01-01
      • 2019-02-18
      • 1970-01-01
      相关资源
      最近更新 更多