7

I am developing an application in which I have to play string as an audio.

I am using http://translate.google.com/translate_tts?tl=en&q=Hello API to speak the string but it is a little bit slow.

Is there any library in objective-c to play string as an audio "Text To Speech".

4

3 回答 3

21

查看 io7 中的 AVSpeechUtterance 和 AVSpeechSynthesizer 类。基本上你可以做到以下几点。

     AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text];
     AVSpeechSynthesizer *syn = [[[AVSpeechSynthesizer alloc] init]autorelease];
    [syn speakUtterance:utterance];
于 2013-08-30T15:55:07.490 回答
9

导入框架:

#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>

.m 文件代码

NSString *str = @"Hello friend, how are you?";

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];

AVSpeechUtterance *speechutt = [AVSpeechUtterance speechUtteranceWithString:strtext];
 speechutt.volume=90.0f;
 speechutt.rate=0.50f;
 speechutt.pitchMultiplier=0.80f;
[speechutt setRate:0.3f];
speechutt.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-us"];
[synthesizer speakUtterance:speechutt];

任何语言的voiceWithLanguage 选项都支持这一点。

Arabic (Saudi Arabia) - ar-SA
Chinese (China) - zh-CN
Chinese (Hong Kong SAR China) - zh-HK
Chinese (Taiwan) - zh-TW
Czech (Czech Republic) - cs-CZ
Danish (Denmark) - da-DK
Dutch (Belgium) - nl-BE
Dutch (Netherlands) - nl-NL
English (Australia) - en-AU
English (Ireland) - en-IE
English (South Africa) - en-ZA
English (United Kingdom) - en-GB
English (United States) - en-US
French (Canada) - fr-CA
French (France) - fr-FR
Finnish (Finland) - fi-FI
German (Germany) - de-DE
Hindi (India) - hi-IN
Hungarian (Hungary) - hu-HU
Indonesian (Indonesia) - id-ID
Italian (Italy) - it-IT
Japanese (Japan) - ja-JP
Korean (South Korea) - ko-KR
Norwegian (Norway) - no-NO
Romanian (Romania) - ro-RO
Russian (Russia) - ru-RU
Slovak (Slovakia) - sk-SK
Spanish (Mexico) - es-MX
Swedish (Sweden) - sv-SE
Turkish (Turkey) - tr-TR
于 2016-12-26T06:31:27.610 回答
0

Nuance NDEV Mobile iOS SDK在质量和性能方面可能是您的最佳选择,但与 OpenEars 不同的是它不是免费的。也就是说,我们有 40 种不同的语言和 61 种不同的声音可用​​,并且该库有一个不依赖于 HTTP(并且仍然基于网络)的子系统,您可以使用它。

一旦你注册了一个帐户..

  • 创建一个意图使用 iOS 平台的应用程序
  • 下载 iOS SDK(那里有一个示例应用程序,但我将描述将其集成到您的应用程序中的过程)
  • 导入 SpeechKit.framework 和相关的框架(参见文档
  • 从上面创建的应用程序的信息中指定凭据
  • SpeechKit使用该信息进行初始化
  • 创建Vocalizer实例,指定语言或语音
  • 将该Vocalizer实例speakString与您要合成的文本一起使用
  • 处理委托方法:
    • willBeginSpeakingString:(NSString *)text
    • didFinishSpeakingString:(NSString *)text

注意:Vocalizer API 也支持SSML

于 2013-07-05T21:37:15.883 回答