Skip to content

Commit 42d9b86

Browse files
committed
修复英文语音转文字时,单词之间没有空格
1 parent 687be92 commit 42d9b86

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
@@ -140,7 +140,7 @@ public void speechToText(View itemView, UiMessage message) {
140140
final String currentAudioUrl = voiceMessage.remoteUrl;
141141

142142
object.put("url", currentAudioUrl);
143-
object.put("noReuse", false);
143+
object.put("noReuse", true);
144144
object.put("noLlm", false);
145145
this.speechToTextSB = new StringBuilder();
146146
this.speechToTextInProgress = true;
@@ -164,7 +164,15 @@ public void onUiEvent(@NonNull EventSource eventSource, @Nullable String id, @Nu
164164
return;
165165
}
166166
if (TextUtils.equals(currentAudioUrl, ((SoundMessageContent) message.message.content).remoteUrl)) {
167-
speechToTextSB.append(data.replaceAll("\n", ""));
167+
if (TextUtils.isEmpty(data)) {
168+
return;
169+
}
170+
char firstChar = data.charAt(0);
171+
if (!speechToTextSB.toString().isEmpty()
172+
&& ((firstChar >= 'a' && firstChar <= 'z') || (firstChar >= 'A' && firstChar <= 'Z'))) {
173+
speechToTextSB.append(" ");
174+
}
175+
speechToTextSB.append(data);
168176
String text = speechToTextSB.toString();
169177
speechToTextTextView.setText(text);
170178
message.audioMessageSpeechToText = text;

0 commit comments

Comments
 (0)