StephennFernandes's picture
CIIL Anuvani-LID
bd48fd1
Raw History Blame Contribute Delete
1.5 kB
#!/usr/bin/env python3
# Copyright (c) 2026, CIIL Anuvani-LID. Apache-2.0.
"""Reference output of the binding tests, from the sherpa-onnx Python package. Every binding test prints
the same JSON lines for the same inputs:
{"file": <clip>, "events": [[label, index, prob], ...]} AudioTagging, all 23 languages, largest first
{"pipeline_file": <recording>, "pipeline": {...}} LidPipeline JSON of the long recording
python3 tests/bindings/python_ref.py <lid model> <vad model> <long wav> <clip.wav> ...
"""
import json
import os
import sys
import sherpa_onnx
import soundfile as sf
def main():
model, vad, long_wav, clips = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4:]
tagger = sherpa_onnx.AudioTagging(sherpa_onnx.AudioTaggingConfig(
model=sherpa_onnx.AudioTaggingModelConfig(lid=model, num_threads=2), top_k=23))
for path in clips:
w, sr = sf.read(path, dtype="float32")
s = tagger.create_stream()
s.accept_waveform(sr, w)
ev = tagger.compute(s)
print(json.dumps({"file": os.path.basename(path), "events": [[e.name, e.index, e.prob] for e in ev]}))
pipe = sherpa_onnx.LidPipeline(sherpa_onnx.LidPipelineConfig(
model=sherpa_onnx.AudioTaggingModelConfig(lid=model, num_threads=2), vad_model=vad))
w, sr = sf.read(long_wav, dtype="float32")
print(json.dumps({"pipeline_file": os.path.basename(long_wav), "pipeline": json.loads(pipe.process(w, sr))}))
if __name__ == "__main__":
main()