Skip to content

Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.

fix(auto): skip blank lines when reading wav.scp and jsonl file lists (#3758)

Grapette.L22b42827a017
diff --git a/funasr/auto/auto_model.py b/funasr/auto/auto_model.py
index 4ff7f13a1..a6635d0e9 100644
--- a/funasr/auto/auto_model.py
+++ b/funasr/auto/auto_model.py
@@ -469,6 +469,8 @@ def prepare_data_iterator(
if file_extension in filelist: # filelist: wav.scp, file.jsonl;text.txt;
with open(data_in, encoding="utf-8") as fin:
for line in fin:
+ if not line.strip():
+ continue
key = "rand_key_" + "".join(random.choice(chars) for _ in range(13))
if data_in.endswith(".jsonl"): # file.jsonl: json.dumps({"source": data})
lines = json.loads(line.strip())
diff --git a/tests/test_pcm_input_format.py b/tests/test_pcm_input_format.py
index 979b9bff2..432834bc3 100644
--- a/tests/test_pcm_input_format.py
+++ b/tests/test_pcm_input_format.py
@@ -97,6 +97,25 @@ def test_default_batch_behavior_is_unchanged():
assert values is data
+def test_scp_filelist_skips_blank_lines(tmp_path):
+ list_path = tmp_path / "wav.scp"
+ list_path.write_text("utt1 /a.wav\n\n \t \nutt2 /b.wav\n", encoding="utf-8")
+ keys, values = prepare_data_iterator(str(list_path))
+ assert keys == ["utt1", "utt2"]
+ assert values == ["/a.wav", "/b.wav"]
+
+
+def test_jsonl_filelist_skips_blank_lines(tmp_path):
+ list_path = tmp_path / "data.jsonl"
+ list_path.write_text(
+ '{"key": "k1", "source": "/a.wav"}\n\n \t \n{"key": "k2", "source": "/b.wav"}\n',
+ encoding="utf-8",
+ )
+ keys, values = prepare_data_iterator(str(list_path))
+ assert keys == ["k1", "k2"]
+ assert values == ["/a.wav", "/b.wav"]
+
+
class _RecordingModel(torch.nn.Module):
def __init__(self, vad=False):
super().__init__()