讯飞语音合成sdk中 分段播放文本功能的实现。
1.建立一个数组,把要分段播放的文本放入数组
2.首先播放数组的第一个记录。 [_iFlySpeechSynthesizer startSpeaking:@"测试语音"];
3. 在onComplete 方法中去播放下一个记录
_iFlySpeechSynthesizer4.注意,由于 _iFlySpeechSynthesizer 是派送单独线程进行 语音播放,在onComplete中无法获得 _iFlySpeechSynthesizer的上下文,所以要用这样的代码:
//把数组中的内容分段阅读,中间加入提示音
-(void) speechWithArray{
if(self.speech_content_array == nil || [self.speech_content_array count] <= 0 ){
return ;
}
[self speechWithString:self.speech_content_array[0] ];
}
-(void) speechWithString:(NSString *) content{
DLog(@"合成语音的内容是%@",content);
[_iFlySpeechSynthesizer startSpeaking:content];
}
/** 播放后结束回调
当整个合成结束之后会回调此函数
@param error 错误码
*/
- (void) onCompleted:(IFlySpeechError*) error{
self.current_speech_number ++;
if (self.current_speech_number < [self.speech_content_array count]){
[self.audioPlayer play];
[self performSelectorOnMainThread:@selector(speechWithString:) withObject:(NSString *)self.speech_content_array[self.current_speech_number] waitUntilDone:NO];
}else{
[self.voiceHud dismissView];
current_msc_status = MSC_Ready;
}
}
<span style="color:#ff0000;">[self performSelectorOnMainThread:@selector(speechWithString:) withObject:(NSString *)self.speech_content_array[self.current_speech_number] waitUntilDone:NO];</span>
这个是关键。