提交 7c171eb0 作者: 王苏进

feat: 优化

上级 83ea0d07
......@@ -475,26 +475,23 @@ static int TTS_MAX_RETRY_COUNT = 3;
self.textFromFlutter = text;
NSLog(@"Start engine, current status: %d", self.engineStarted);
if (!self.engineStarted) {
// [self clearResult:nil];
self.engineErrorOccurred = FALSE;
self.engineErrorOccurred = FALSE;
// Directive:启动引擎前调用SYNC_STOP指令,保证前一次请求结束。
NSLog(@"关闭引擎(同步)");
NSLog(@"Directive: SEDirectiveSyncStopEngine");
SEEngineErrorCode ret = [self.curEngine sendDirective:SEDirectiveSyncStopEngine];
if (ret != SENoError) {
NSLog(@"Send directive syncstop failed: %d", ret);
} else {
[self configStartTtsParams];
// Directive:启动引擎前调用SYNC_STOP指令,保证前一次请求结束。
NSLog(@"关闭引擎(同步)");
NSLog(@"Directive: SEDirectiveSyncStopEngine");
SEEngineErrorCode ret = [self.curEngine sendDirective:SEDirectiveSyncStopEngine];
if (ret != SENoError) {
NSLog(@"Send directive syncstop failed: %d", ret);
} else {
[self configStartTtsParams];
NSLog(@"启动引擎.");
NSLog(@"Directive: SEDirectiveStartEngine");
SEEngineErrorCode ret = [self.curEngine sendDirective:SEDirectiveStartEngine];
if (SENoError != ret) {
NSString* message = [NSString stringWithFormat:@"发送启动引擎指令失败: %d", ret];
[self sendStartEngineDirectiveFailed:message];
}
NSLog(@"启动引擎.");
NSLog(@"Directive: SEDirectiveStartEngine");
SEEngineErrorCode ret = [self.curEngine sendDirective:SEDirectiveStartEngine];
if (SENoError != ret) {
NSString* message = [NSString stringWithFormat:@"发送启动引擎指令失败: %d", ret];
[self sendStartEngineDirectiveFailed:message];
}
}
}
......@@ -693,29 +690,29 @@ static int TTS_MAX_RETRY_COUNT = 3;
// 根据 SDK 返回的播放进度高亮正在播放的文本,用红色表示
// 根据 SDK 返回的合成开始和合成结束回调高亮正在合成的文本,用蓝色表示
-(void)updatePlayingWords:(NSString*) playingId {
int synthesisIndex = self.ttsSynthesisIndex;
NSNumber* val = [self.ttsSynthesisMap objectForKey:playingId];
if (val != nil) {
self.ttsPlayingIndex = [val intValue];
}
int beginIndex = MAX(self.ttsPlayingIndex, 0);
int maxSentencesDisplayed = MIN((int)[self.ttsSynthesisText count], 16);
// int synthesisIndex = self.ttsSynthesisIndex;
// NSNumber* val = [self.ttsSynthesisMap objectForKey:playingId];
// if (val != nil) {
// self.ttsPlayingIndex = [val intValue];
// }
//
// int beginIndex = MAX(self.ttsPlayingIndex, 0);
// int maxSentencesDisplayed = MIN((int)[self.ttsSynthesisText count], 500);
//
//// NSString *resultStr = @"";
// for (int cnt = 0; cnt < maxSentencesDisplayed; ++cnt) {
// int index = (beginIndex + cnt) % [self.ttsSynthesisText count];
// NSString* current_sentence = self.ttsSynthesisText[index];
//// NSInteger playedPosition = 0;
// if (index == self.ttsPlayingIndex) {
//// playedPosition = MIN(ceil((double)(self.ttsPlayingProgress) * (double)([current_sentence length])), [current_sentence length]);
//// NSLog(@"played position: %ld", (long)playedPosition);
//
//
// }
//
// }
NSString *resultStr = @"";
for (int cnt = 0; cnt < maxSentencesDisplayed; ++cnt) {
int index = (beginIndex + cnt) % [self.ttsSynthesisText count];
NSString* current_sentence = self.ttsSynthesisText[index];
NSInteger playedPosition = 0;
if (index == self.ttsPlayingIndex) {
playedPosition = MIN(ceil((double)(self.ttsPlayingProgress) * (double)([current_sentence length])), [current_sentence length]);
NSLog(@"played position: %ld", (long)playedPosition);
resultStr = [resultStr stringByAppendingString:[current_sentence substringToIndex:playedPosition]];
}
if([ self.delegate respondsToSelector:@selector(onRecieve:)]) {
[self.delegate onRecieve:@{@"playWords": resultStr}];
}
}
// [self.resultTextView setAttributedText:resultStr];
}
......@@ -745,6 +742,11 @@ static int TTS_MAX_RETRY_COUNT = 3;
// self.pauseResumeButton.enabled = TRUE;
self.ttsPlayingProgress = 0.0;
[self updatePlayingWords:playingId];
if([self.delegate respondsToSelector:@selector(onRecieve:)]) {
int index = [[self.ttsSynthesisMap objectForKey:playingId] intValue];
[self.delegate onRecieve:@{@"playWords": self.ttsSynthesisText[index]}];
}
});
}
......@@ -786,6 +788,7 @@ static int TTS_MAX_RETRY_COUNT = 3;
if([[self.ttsSynthesisMap allKeys] count] == 0) {
NSLog(@"这里告诉flutter 已经全部读完了");
[self.delegate onRecieve:@{@"finish": @(YES)}];
[self resetTtsContext];
}
});
if (self.ttsSynthesisFromPlayer) {
......@@ -811,12 +814,15 @@ static int TTS_MAX_RETRY_COUNT = 3;
}
- (void)synthesisNextSentence {
self.ttsSynthesisIndex = (self.ttsSynthesisIndex + 1) % [self.ttsSynthesisText count];
self.ttsSynthesisIndex += 1;
// 合成最后一条后停止
if (!self.ttsSynthesisFromPlayer && (self.ttsSynthesisIndex +1) < self.ttsSynthesisText.count) {
// && ((self.ttsSynthesisIndex +1) < self.ttsSynthesisText.count)
NSLog(@"合成下后一条%@",@(self.ttsSynthesisIndex));
if (!self.ttsSynthesisFromPlayer && ((self.ttsSynthesisIndex +1) <= self.ttsSynthesisText.count)) {
[self triggerSynthesis];
}
}
-(void)triggerSynthesis {
......@@ -954,8 +960,6 @@ static int TTS_MAX_RETRY_COUNT = 3;
}
}
- (void)onRecieve:(nonnull NSDictionary *)message {
}
@end
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论