hzeng412 Claude Fable 5 commited on
Commit
21dbad4
·
1 Parent(s): 3c70498

ASR: use auto language detection to reject non-speech (fixes hallucination)

Browse files

Forcing a language makes Qwen3-ASR output transcription text
unconditionally, so silence/noise segments that slip through VAD
produce hallucinated words (FunASR/Whisper do this on every such
segment). In auto mode the model returns an empty string for
non-speech, which the pipeline already drops.

Verified: silence, low and medium noise -> '' ; zh/en speech unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

src/voice_dialogue/asr/models/qwen.py CHANGED
@@ -10,12 +10,6 @@ from voice_dialogue.asr.models.base import ASRInterface
10
  from voice_dialogue.asr.utils import ensure_minimum_audio_duration
11
  from voice_dialogue.utils.logger import logger
12
 
13
- # Qwen3-ASR 的 language 参数使用语言全名
14
- LANGUAGE_NAME_MAPPING = {
15
- 'zh': 'Chinese',
16
- 'en': 'English',
17
- }
18
-
19
  DEFAULT_MODEL = os.environ.get('QWEN_ASR_MODEL', 'Qwen/Qwen3-ASR-1.7B')
20
 
21
  TARGET_SAMPLE_RATE = 16000
@@ -60,11 +54,11 @@ class QwenASRClient(ASRInterface):
60
  def transcribe(self, audio_array: np.ndarray, language: str = None) -> str:
61
  audio_array = ensure_minimum_audio_duration(audio_array)
62
 
63
- # 未指定语言时交给模型自动检测(Qwen3-ASR 自带语种识别)
64
- qwen_language = LANGUAGE_NAME_MAPPING.get(language)
65
-
66
  results = self.model.transcribe(
67
  audio=(audio_array, TARGET_SAMPLE_RATE),
68
- language=qwen_language,
69
  )
70
  return ' '.join(result.text for result in results).strip()
 
10
  from voice_dialogue.asr.utils import ensure_minimum_audio_duration
11
  from voice_dialogue.utils.logger import logger
12
 
 
 
 
 
 
 
13
  DEFAULT_MODEL = os.environ.get('QWEN_ASR_MODEL', 'Qwen/Qwen3-ASR-1.7B')
14
 
15
  TARGET_SAMPLE_RATE = 16000
 
54
  def transcribe(self, audio_array: np.ndarray, language: str = None) -> str:
55
  audio_array = ensure_minimum_audio_duration(audio_array)
56
 
57
+ # 始终使用自动语种检测:指定语言会强制模型"只输出转写文本",
58
+ # 静音/噪声段会被迫编出幻听文字;自动模式下非语音段返回空串,
59
+ # 由上游丢弃,从根上消除幻听。
60
  results = self.model.transcribe(
61
  audio=(audio_array, TARGET_SAMPLE_RATE),
62
+ language=None,
63
  )
64
  return ' '.join(result.text for result in results).strip()