Skip to content

Commit 5711125

Browse files
committed
优化语音转文字展示效果
1 parent 42d9b86 commit 5711125

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

uikit/src/main/java/cn/wildfire/chat/kit/conversation/message/viewholder/AudioMessageContentViewHolder.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,19 @@ public void onUiEvent(@NonNull EventSource eventSource, @Nullable String id, @Nu
168168
return;
169169
}
170170
char firstChar = data.charAt(0);
171-
if (!speechToTextSB.toString().isEmpty()
171+
String curText = speechToTextSB.toString();
172+
if (!curText.isEmpty()
172173
&& ((firstChar >= 'a' && firstChar <= 'z') || (firstChar >= 'A' && firstChar <= 'Z'))) {
173174
speechToTextSB.append(" ");
175+
speechToTextSB.append(data);
176+
177+
char lastChar = curText.charAt(curText.length() - 1);
178+
if (!((lastChar >= 'a' && lastChar <= 'z') || (lastChar >= 'A' && lastChar <= 'Z'))) {
179+
speechToTextSB.append(" ");
180+
}
181+
} else {
182+
speechToTextSB.append(data);
174183
}
175-
speechToTextSB.append(data);
176184
String text = speechToTextSB.toString();
177185
speechToTextTextView.setText(text);
178186
message.audioMessageSpeechToText = text;

0 commit comments

Comments
 (0)