Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/granite_switch/vllm/audio/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def _load_chunking():

# Sample rate every supported ASR front-end expects.
_TARGET_SAMPLE_RATE = 16_000
_NO_SPEECH_TEXT = "<|nospeech|>"

# Audio item shapes vLLM may pass to a multimodal processor.
AudioInput = Union[
Expand Down Expand Up @@ -320,7 +321,11 @@ def _run_pipeline(
**call_kwargs,
)
text = result["text"] if isinstance(result, dict) else str(result)
return text.strip()
text = text.strip()
# Some multilingual CTC checkpoints emit this control token for
# silence or non-speech. Treat it as an empty transcript so it cannot
# be inserted into the LLM prompt as if it were user speech.
return "" if text == _NO_SPEECH_TEXT else text


# ── Module-level cache + convenience function ────────────────────────────────
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ def test_transcribe_strips_and_uses_target_rate(self):
passed = fake_pipe.call_args_list[-1][0][0]
assert passed["sampling_rate"] == 16000

def test_transcribe_drops_no_speech_control_token(self):
t = asr.ASRTranscriber(model_id="x", device="cpu")
t._pipeline = mock.Mock(return_value={"text": " <|nospeech|> "})

out = t.transcribe(np.zeros(1600, dtype=np.float32), sampling_rate=16000)

assert out == ""

def test_load_is_idempotent_when_pipeline_set(self):
# Once the pipeline is loaded, load() must early-return (no rebuild).
t = asr.ASRTranscriber(model_id="x", device="cpu")
Expand Down