From 90dfe73f1a1b6815cfba08ec165394719005e4cf Mon Sep 17 00:00:00 2001
From: Ariver <shanghai3168@gmail.com>
Date: Sun, 07 Jun 2026 01:48:32 +0800
Subject: [PATCH] Fix X-ASR CJK spacing

---
 privatevoice.src/internal/textproc/textproc.go |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/privatevoice.src/internal/textproc/textproc.go b/privatevoice.src/internal/textproc/textproc.go
index 44d9cdb..60683de 100755
--- a/privatevoice.src/internal/textproc/textproc.go
+++ b/privatevoice.src/internal/textproc/textproc.go
@@ -59,8 +59,31 @@
 	return strings.TrimSpace(text)
 }
 
+func removeSpacesBetweenCJK(text string) string {
+	runes := []rune(text)
+	buf := make([]rune, 0, len(runes))
+
+	for i := 0; i < len(runes); i++ {
+		r := runes[i]
+		if unicode.IsSpace(r) {
+			j := i
+			for j < len(runes) && unicode.IsSpace(runes[j]) {
+				j++
+			}
+			if len(buf) > 0 && j < len(runes) && isCJK(buf[len(buf)-1]) && isCJK(runes[j]) {
+				i = j - 1
+				continue
+			}
+		}
+		buf = append(buf, r)
+	}
+
+	return string(buf)
+}
+
 // PostProcess cleans up mixed Chinese-English text from SenseVoice:
 //   - Strips special tokens (<|zh|>, <|NEUTRAL|>, etc.)
+//   - Removes model-added spaces between CJK characters
 //   - Inserts spaces between CJK characters and ASCII letters/digits
 //   - Capitalizes the first letter and letters after sentence-ending punctuation
 //   - Collapses multiple spaces
@@ -78,6 +101,8 @@
 		return text
 	}
 
+	text = removeSpacesBetweenCJK(text)
+
 	// Insert spaces at CJK ↔ ASCII alphanumeric boundaries
 	runes := []rune(text)
 	buf := make([]rune, 0, len(runes)+16)

--
Gitblit v1.9.3