訊飛語音我就不介紹了,說實話,昨晚之前我還不知道這個東西.因為自己現在只用到了語音合成,即將一段文字轉化為語音,所以在此先將語音合成的方法列出來.
首先添加框架
iflyMSC.framework,
libz.dylib/libz.tbd(Xcode7.x)
AVFoundation.framework
SystemConfiguration.framework
Foundation.framework
CoreTelephoney.framework
AudioToolbox.framework
UIKit.framework
CoreLocation.framework
AddressBook.framework
QuartzCore.framework
CoreGraphics.framework
說實話,框架好多,並且大多數都是目前用不到,不過考慮到以後這篇文章還會繼續增加,所以就一次貼出來吧.
//設置sdk的log等級,log保存在下面設置的工作路徑中 [IFlySetting setLogFile:LVL_ALL]; //打開輸出在console的log開關 [IFlySetting showLogcat:YES]; //設置sdk的工作路徑 NSString *paths=NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0]; [IFlySetting setLogFilePath:paths]; //創建語音配置,appid必須要傳入,僅執行一次則可 NSString *initString=[[NSString alloc]initWithFormat:@"appid=%@",APPID_VALUE]; //所有服務啟動前,需要確保執行createUtility [IFlySpeechUtility createUtility:initString];
語音合成
@interface ViewController ()<IFlySpeechSynthesizerDelegate>
{
//需要實現IFlySpeechSynthesizerDelegate合成會話的服務代理
IFlySpeechSynthesizer *_iFlySpeechSynthesizer;
}
- (IBAction)read:(UIButton *)sender { //1.創建合成對象 _iFlySpeechSynthesizer=[IFlySpeechSynthesizer sharedInstance]; _iFlySpeechSynthesizer.delegate=self; //2.設置合成參數 //設置在線工作方式 [_iFlySpeechSynthesizer setParameter:[IFlySpeechConstant TYPE_CLOUD] forKey:[IFlySpeechConstant ENGINE_TYPE]]; //音量,取值范圍 0~100 [_iFlySpeechSynthesizer setParameter:@"50" forKey:[IFlySpeechConstant VOLUME]]; //說話語速 [_iFlySpeechSynthesizer setParameter:@"42" forKey:[IFlySpeechConstant SPEED]]; //發音人,默認為”xiaoyan”,可以設置的參數列表可參考“合成發音人列表” [_iFlySpeechSynthesizer setParameter:@"xiaoyan" forKey:[IFlySpeechConstant VOICE_NAME]]; //保存合成文件名,如不再需要,設置設置為nil或者為空表示取消,默認目錄位於 library/cache下 [_iFlySpeechSynthesizer setParameter:@"tts.pcm" forKey:[IFlySpeechConstant TTS_AUDIO_PATH]]; //3.啟動合成會話 [_iFlySpeechSynthesizer startSpeaking:_world.text]; }
IFlySpeechSynthesizerDelegate協議方法
//結束代理 -(void)onCompleted:(IFlySpeechError *)error { NSLog(@"結束代理"); } //合成開始 -(void)onSpeakBegin { NSLog(@"合成開始"); } //合成緩沖進度 -(void)onBufferProgress:(int)progress message:(NSString *)msg { NSLog(@"合成緩沖進度"); } //合成播放進度 -(void)onSpeakProgress:(int)progress { NSLog(@"合成緩沖進度"); }
PS:說實話,感覺就像是從幫助文檔上照抄一樣