Text to speech in objective-c iPhone

2019-03-20 18:53发布

问题:

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".

回答1:

Look at the classes AVSpeechUtterance and AVSpeechSynthesizer in io7. Basically you can just do the following.

     AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text];
     AVSpeechSynthesizer *syn = [[[AVSpeechSynthesizer alloc] init]autorelease];
    [syn speakUtterance:utterance];


回答2:

import frameworks :

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

.m file code

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 option in any language to speek supported that.

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


回答3:

The Nuance NDEV Mobile iOS SDK could be your best bet, in terms of quality and performance, but unlike OpenEars is not free. That said, we've got 40 different languages and 61 different voices available, and the library has a subsystem that doesn't rely on HTTP (and is still network based) that you can play with.

Once you've signed up for an account..

  • Create an application with the intent to use the iOS platform
  • Download the iOS SDK (there's a sample app in there, but i'll describe the process to integrate it into your app)
  • Import the SpeechKit.framework, and associated frameworks (see docs)
  • Specify the credentials from the info from the app created above
  • Initialize SpeechKit with that information
  • Create a Vocalizer instance, specifying the language or voice
  • Use that Vocalizer instance to speakString with the text you want to synthesize
  • Handle the delegate methods:
    • willBeginSpeakingString:(NSString *)text
    • didFinishSpeakingString:(NSString *)text

Note: The Vocalizer API also supports SSML.