AVSpeechSynthesizer is a speechsynthesizer with a few open interfaces, which can hardly meet the needs of our development. In this case, third-party speech is the best choice.

Text To Speech technology, also known as TTS, is used in iOS for speechsynthesizer and other features such as audio books. A speech synthesizer, which can be imagined as an avspeechvoice, is the main interfaceCopy the code

Baidu Voice package, I choose Baidu voice package! 2.1 Download the offline synthetic voice package

-(void)configureSDK{
    NSLog(@"TTS version info: %@", [BDSSpeechSynthesizer version]);
    [BDSSpeechSynthesizer setLogLevel:BDS_PUBLIC_LOG_VERBOSE];
    [[BDSSpeechSynthesizer sharedInstance] setSynthesizerDelegate:self]; [self configureOnlineTTS]; [self configureOfflineTTS]; } // The configuration is online -(void)configureOnlineTTS{//#error "Set api key and secret key"
    [[BDSSpeechSynthesizer sharedInstance] setApiKey:@"e7QA3FWob8EbzLDP7I6fCtcY" withSecretKey:@"17d90e1974d0bcb31725245f96718e73"]; } // Configure offline -(void)configureOfflineTTS{NSString* offlineEngineSpeechData = [[NSBundle mainBundle] pathForResource:@"Chinese_Speech_Female" ofType:@"dat"];
    NSString* offlineEngineTextData = [[NSBundle mainBundle] pathForResource:@"Chinese_Text" ofType:@"dat"];
    NSString* offlineEngineEnglishSpeechData = [[NSBundle mainBundle] pathForResource:@"English_Speech_Female" ofType:@"dat"];
    NSString* offlineEngineEnglishTextData = [[NSBundle mainBundle] pathForResource:@"English_Text" ofType:@"dat"];
    NSString* offlineEngineLicenseFile = [[NSBundle mainBundle] pathForResource:@"offline_engine_tmp_license" ofType:@"dat"];
    //#error "set offline engine license"
    NSError* err = [[BDSSpeechSynthesizer sharedInstance] loadOfflineEngine:offlineEngineTextData speechDataPath:offlineEngineSpeechData licenseFilePath:offlineEngineLicenseFile withAppCode:@"9353239"]; //
    if (err) {
        return;
    }
    err = [[BDSSpeechSynthesizer sharedInstance] loadEnglishDataForOfflineEngine:offlineEngineEnglishTextData speechData:offlineEngineEnglishSpeechData];
    if (err) {
        return; }} / / play failure - (void) synthesizerErrorOccurred: (NSError *) error SpeakSentence speaking: (NSInteger) synthesizing:(NSInteger)SynthesizeSentence{ [[BDSSpeechSynthesizer sharedInstance] cancel]; [[BDSSpeechSynthesizer sharedInstance]]setSynthesizerParam:[NSNumber numberWithInt:BDS_SYNTHESIZER_SPEAKER_FEMALE] forKey:BDS_SYNTHESIZER_PARAM_SPEAKER ]; [[BDSSpeechSynthesizer sharedInstance]setSynthesizerParam:[NSNumber numberWithInt:5] forKey:BDS_SYNTHESIZER_PARAM_VOLUME]; // Sonic synthesizer [[BDSSpeechSynthesizer sharedInstance]setSynthesizerParam:[NSNumber numberWithInt:5] forKey:BDS_SYNTHESIZER_PARAM_SPEED]; [[BDSSpeechSynthesizer sharedInstance]setSynthesizerParam:[NSNumber numberWithInt:5] forKey:BDS_SYNTHESIZER_PARAM_PITCH]; [[BDSSpeechSynthesizer sharedInstance]setSynthesizerParam:[NSNumber numberWithInt: BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_16K] forKey:BDS_SYNTHESIZER_PARAM_AUDIO_ENCODING ];
Copy the code

Finally, the demo portal is attached

Iii. Iflytek Voice (a relatively mainstream one)