Commit 4233927

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-05-26 01:54:47
fix(asr): add space after English words in Tencent ASR
1 parent fbb1e2d
Changed files (2)
src/asr/tecent_asr.py
@@ -10,7 +10,7 @@ import anyio
 from glom import Coalesce, flatten, glom
 from loguru import logger
 
-from asr.utils import downsampe_audio
+from asr.utils import downsampe_audio, is_english_word
 from config import ASR, FILE_SERVER
 from database import delete_alist, upload_alist, upload_uguu
 from networking import hx_req
@@ -224,6 +224,8 @@ def generate_tencent_transcription(sentence_start_ms: list[int], words: list[lis
                 sentence = glom(item, Coalesce("Word", "word"), default="")
                 if not sentence:
                     continue
+                if is_english_word(sentence):
+                    sentence = sentence + " "
                 if idx == 0 or res.endswith((".", "。", "?", "?")):  # noqa: RUF001
                     start_seconds = float(glom(item, Coalesce("StartTime", "OffsetStartMs", "start_time"), default=0) + float(start_offset)) // 1000
                     minutes = int(start_seconds // 60)
src/asr/utils.py
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 import random
+import re
 from pathlib import Path
 
 from config import ASR, GEMINI
@@ -74,3 +75,7 @@ def downsampe_audio(path: str | Path, ext: str = "opus", codec: str = "libopus",
     if not path.is_file():
         return path
     return convert_to_audio(path, ext=ext, codec=codec, ar=sample_rate, **kwargs)
+
+
+def is_english_word(text: str) -> bool:
+    return bool(re.match(r"^[a-zA-Z]+$", text))