有關整合科大訊飛sdk的語音(三)語音合成
@property (nonatomic, strong) IFlySpeechSynthesizer *iFlySpeechSynthesizer;//語音合成
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.iFlySpeechSynthesizer startSpeaking: @"正在搜尋..."];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//記住釋放掉
[self.iFlySpeechSynthesizer stopSpeaking];
self.iFlySpeechSynthesizer = nil;
[IFlySpeechSynthesizer destroy];
}
- (IFlySpeechSynthesizer *)iFlySpeechSynthesizer{
if (!_iFlySpeechSynthesizer) {
//獲取語音合成單例
_iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance];
//設定協議委託物件
_iFlySpeechSynthesizer.delegate = self;
//設定合成引數
//設定線上工作方式
[_iFlySpeechSynthesizer setParameter:[IFlySpeechConstant TYPE_CLOUD]
forKey:[IFlySpeechConstant ENGINE_TYPE]];
//設定音量,取值範圍 0~100
[_iFlySpeechSynthesizer setParameter:@"100"
forKey: [IFlySpeechConstant VOLUME]];
//發音人,預設為”xiaoyan”,可以設定的引數列表可參考“合成發音人列表”
[_iFlySpeechSynthesizer setParameter:@" xiaoyan "
forKey: [IFlySpeechConstant VOICE_NAME]];
//儲存合成檔名,如不再需要,設定為nil或者為空表示取消,預設目錄位於library/cache下
[_iFlySpeechSynthesizer setParameter:nil
forKey: [IFlySpeechConstant TTS_AUDIO_PATH]];
}
return _iFlySpeechSynthesizer;
}
#pragma mark - IFlySpeechSynthesizerDelegate協議實現
//合成結束
- (void) onCompleted:(IFlySpeechError *) error {
NSLog(@"%s,error=%d",__func__,error.errorCode);
if (error.errorCode != 0) {
return;
}
}
//合成開始
- (void) onSpeakBegin {
}
//合成緩衝進度
- (void) onBufferProgress:(int) progress message:(NSString *)msg {
}
//合成播放進度
- (void) onSpeakProgress:(int) progress beginPos:(int)beginPos endPos:(int)endPos {
if (progress == 100 ) {
// 合成結束後,可進行一些類似跳轉的操作
}else{
}
}