百度TTS語音播報

前言

之前我的簡書中寫到了【iOS實現(xiàn)語音播報】里面有介紹到兩種語音播報方式:AVSpeechSynthesis和百度TTS,這篇文章我們就簡單的了解一下百度TTS到底該如何使用?

正文

1.百度TTS集成

TTS的集成我就不多說了,大家可以通過百度TTS集成進(jìn)行查看和學(xué)習(xí)!

2.使用

不管是【極光推送】還是【TTS】第一步少不了申請APPKey,然后在我們的工程中注冊

// 注冊
-(void)configureTTSSDK{
    NSLog(@"TTS version info: %@", [BDSSpeechSynthesizer version]);
    [BDSSpeechSynthesizer setLogLevel:BDS_PUBLIC_LOG_VERBOSE];
    [[BDSSpeechSynthesizer sharedInstance] setSynthesizerDelegate:self];
//    [self configureOnlineTTS];
    [self configureOfflineTTS];
    
}

// 在線注冊
-(void)configureOnlineTTS{
    
    [[BDSSpeechSynthesizer sharedInstance] setApiKey:BaiDu_API_Key withSecretKey:BaiDu_Secret_Key];
    
    [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:nil];
    
}
//離線注冊
-(void)configureOfflineTTS{
    
    NSError *err = nil;
    // 在這里選擇不同的離線音庫(請在XCode中Add相應(yīng)的資源文件),同一時間只能load一個離線音庫。根據(jù)網(wǎng)絡(luò)狀況和配置,SDK可能會自動切換到離線合成。
    
    NSString* offlineEngineSpeechData = [[NSBundle mainBundle] pathForResource:@"Chinese_And_English_Speech_Female" ofType:@"dat"];
    
    NSString* offlineChineseAndEnglishTextData = [[NSBundle mainBundle] pathForResource:@"Chinese_And_English_Text" ofType:@"dat"];
    
    err = [[BDSSpeechSynthesizer sharedInstance] loadOfflineEngine:offlineChineseAndEnglishTextData speechDataPath:offlineEngineSpeechData licenseFilePath:nil withAppCode:BaiDu_APP_ID];
    if(err){
        NSLog(@"offLineTTS configure error : %@",err.localizedDescription);
    }else{
        NSLog(@"offLineTTS success");
    }
}

- (void)ttsReadContent:(NSString *) message{
    [[BDSSpeechSynthesizer sharedInstance] setPlayerVolume:5];
    [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithInteger:7] forKey:BDS_SYNTHESIZER_PARAM_SPEED];
    NSInteger flag = [[BDSSpeechSynthesizer sharedInstance] speakSentence:message withError:nil];
    NSLog(@"TTSFlage -------%ld",flag);
}

不難吧!是不是很簡單!也就這樣。。。。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容