@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{
}
}