提交 7c171eb0 作者: 王苏进

feat: 优化

上级 83ea0d07
...@@ -475,8 +475,6 @@ static int TTS_MAX_RETRY_COUNT = 3; ...@@ -475,8 +475,6 @@ static int TTS_MAX_RETRY_COUNT = 3;
self.textFromFlutter = text; self.textFromFlutter = text;
NSLog(@"Start engine, current status: %d", self.engineStarted); NSLog(@"Start engine, current status: %d", self.engineStarted);
if (!self.engineStarted) {
// [self clearResult:nil];
self.engineErrorOccurred = FALSE; self.engineErrorOccurred = FALSE;
// Directive:启动引擎前调用SYNC_STOP指令,保证前一次请求结束。 // Directive:启动引擎前调用SYNC_STOP指令,保证前一次请求结束。
...@@ -496,7 +494,6 @@ static int TTS_MAX_RETRY_COUNT = 3; ...@@ -496,7 +494,6 @@ static int TTS_MAX_RETRY_COUNT = 3;
[self sendStartEngineDirectiveFailed:message]; [self sendStartEngineDirectiveFailed:message];
} }
} }
}
} }
- (void)stopEngineBtnClicked{ - (void)stopEngineBtnClicked{
...@@ -693,29 +690,29 @@ static int TTS_MAX_RETRY_COUNT = 3; ...@@ -693,29 +690,29 @@ static int TTS_MAX_RETRY_COUNT = 3;
// 根据 SDK 返回的播放进度高亮正在播放的文本,用红色表示 // 根据 SDK 返回的播放进度高亮正在播放的文本,用红色表示
// 根据 SDK 返回的合成开始和合成结束回调高亮正在合成的文本,用蓝色表示 // 根据 SDK 返回的合成开始和合成结束回调高亮正在合成的文本,用蓝色表示
-(void)updatePlayingWords:(NSString*) playingId { -(void)updatePlayingWords:(NSString*) playingId {
int synthesisIndex = self.ttsSynthesisIndex; // int synthesisIndex = self.ttsSynthesisIndex;
NSNumber* val = [self.ttsSynthesisMap objectForKey:playingId]; // NSNumber* val = [self.ttsSynthesisMap objectForKey:playingId];
if (val != nil) { // if (val != nil) {
self.ttsPlayingIndex = [val intValue]; // self.ttsPlayingIndex = [val intValue];
} // }
//
int beginIndex = MAX(self.ttsPlayingIndex, 0); // int beginIndex = MAX(self.ttsPlayingIndex, 0);
int maxSentencesDisplayed = MIN((int)[self.ttsSynthesisText count], 16); // 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]; // [self.resultTextView setAttributedText:resultStr];
} }
...@@ -745,6 +742,11 @@ static int TTS_MAX_RETRY_COUNT = 3; ...@@ -745,6 +742,11 @@ static int TTS_MAX_RETRY_COUNT = 3;
// self.pauseResumeButton.enabled = TRUE; // self.pauseResumeButton.enabled = TRUE;
self.ttsPlayingProgress = 0.0; self.ttsPlayingProgress = 0.0;
[self updatePlayingWords:playingId]; [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; ...@@ -786,6 +788,7 @@ static int TTS_MAX_RETRY_COUNT = 3;
if([[self.ttsSynthesisMap allKeys] count] == 0) { if([[self.ttsSynthesisMap allKeys] count] == 0) {
NSLog(@"这里告诉flutter 已经全部读完了"); NSLog(@"这里告诉flutter 已经全部读完了");
[self.delegate onRecieve:@{@"finish": @(YES)}]; [self.delegate onRecieve:@{@"finish": @(YES)}];
[self resetTtsContext];
} }
}); });
if (self.ttsSynthesisFromPlayer) { if (self.ttsSynthesisFromPlayer) {
...@@ -811,12 +814,15 @@ static int TTS_MAX_RETRY_COUNT = 3; ...@@ -811,12 +814,15 @@ static int TTS_MAX_RETRY_COUNT = 3;
} }
- (void)synthesisNextSentence { - (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]; [self triggerSynthesis];
} }
} }
-(void)triggerSynthesis { -(void)triggerSynthesis {
...@@ -954,8 +960,6 @@ static int TTS_MAX_RETRY_COUNT = 3; ...@@ -954,8 +960,6 @@ static int TTS_MAX_RETRY_COUNT = 3;
} }
} }
- (void)onRecieve:(nonnull NSDictionary *)message {
}
@end @end
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论