Skip to content

Commit 7a1e15b

Browse files
ZhaoChaoqunclaude
andcommitted
Remove spaces between Chinese and English text
- Add post-processing to remove spaces between Chinese and alphanumeric characters - Update mergeTexts comment to reflect current behavior Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6b62142 commit 7a1e15b

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Sources/RecordingManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class RecordingManager {
192192
}
193193
}
194194

195-
// 无重叠,直接拼接(无空格,因为中文不需要)
195+
// 无重叠,信任模型输出的标点,直接拼接
196196
return existing + new
197197
}
198198

Sources/SherpaOnnxRecognizer.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ class SherpaOnnxRecognizer {
8383
// 过滤 FunASR 特殊标记(如 <|nospeech|>, <|HAPPY|>, <|en|> 等)
8484
var text = String(cString: textPtr)
8585
text = text.replacingOccurrences(of: "<\\|[^|]+\\|>", with: "", options: .regularExpression)
86+
87+
// 移除中文和英文之间的空格
88+
text = text.replacingOccurrences(of: "([\\u4e00-\\u9fa5])\\s+([a-zA-Z0-9])", with: "$1$2", options: .regularExpression)
89+
text = text.replacingOccurrences(of: "([a-zA-Z0-9])\\s+([\\u4e00-\\u9fa5])", with: "$1$2", options: .regularExpression)
90+
8691
text = text.trimmingCharacters(in: .whitespacesAndNewlines)
8792
return text.isEmpty ? nil : text
8893
}

0 commit comments

Comments
 (0)