# Inference Examples For a task-first tutorial, start with [31 tasks and five audio examples each](TASKS.md). Then follow [benchmark acquisition/evaluation](../benchmark/README.md) and [custom data/fine-tuning](../finetune/README.md). Complete the repository's [Quick Start](../README.md#quick-start) first. All commands and Python examples below run from the repository root, using `JEV_CHECKPOINT` and `CUDA_VISIBLE_DEVICES` from that setup. Create a fresh output directory for these examples. Existing output files are never overwritten. ```bash mkdir -p runs JEV_RUN_DIR=$(mktemp -d "$PWD/runs/examples.XXXXXX") ``` - [Non-streaming](#non-streaming): Qwen-Audio-3.1-Jev and Qwen-Audio-3.1-Jev-Tiny. - [Streaming](#streaming-qwen-audio-31-jev-tiny): Qwen-Audio-3.1-Jev-Tiny. - [Task-by-task demos](TASKS.md): 31 task templates, including the official page's use cases. - [Audio sources and attribution](AUDIO_ATTRIBUTION.md). - [Calling Examples](CALLING_EXAMPLES.md): copy-ready Choice, Noul, Score and Streaming patterns. ## Bundled Audio All WAV files below are included in [audios/](audios/); no separate audio download is required. Streaming requests reuse these clips. | Example request | Included audio | | --- | --- | | [Choice](choice.json) | [choice.wav](audios/choice.wav) | | [Noul / speaker verification](noul.json) | [noul-reference.wav](audios/noul-reference.wav), [noul-comparison.wav](audios/noul-comparison.wav) | | [Score / speech quality](score.json) | [score.wav](audios/score.wav) | | [Streaming VAD](streaming_vad.json) | [noul-reference.wav](audios/noul-reference.wav) | | [Streaming SNR](streaming_snr.json) | [score.wav](audios/score.wav) | See [Audio Sources and Attribution](AUDIO_ATTRIBUTION.md) for dataset origins and licenses. The requests demonstrate the interfaces; use audio and criteria suited to your checkpoint when evaluating a task. ## Non-streaming For audio QA, intent, dialect, turn completion, quality dimensions, and other task-specific commands, start with [Task Demos](TASKS.md). The examples below introduce the three interfaces and the Python API. ### Command line Each JSON file contains one question, its criteria, and one or two audio paths. The commands below use Hugging Face. In the [FunASR vLLM environment](../docs/vllm.md#installation), add `--backend vllm` to run the same Choice, Noul, and Score requests. ```bash # Choice: classify an instrument. qwen-audio-jev --input examples/choice.json --output "$JEV_RUN_DIR/choice.json" # Noul: determine whether two recordings contain the same speaker. qwen-audio-jev --input examples/noul.json --output "$JEV_RUN_DIR/noul.json" # Score: rate perceived speech quality on a 1–5 MOS scale. qwen-audio-jev --input examples/score.json --output "$JEV_RUN_DIR/score.json" ``` To use your own audio, copy a request JSON and edit its audio paths, question, and criteria. Paths in JSON are relative to that JSON file. Attachments are named `audio_0` and `audio_1` in input order. See the [input/output protocol](../docs/input-output.md) for all fields and response formats. ### Custom question from the command line Paths passed to `--audio` are relative to the current working directory. ```bash qwen-audio-jev --task noul \ --question 'Are audio_0 and audio_1 spoken by the same person?' \ --criteria '{"true":"Same speaker","false":"Different speakers"}' \ --audio examples/audios/noul-reference.wav examples/audios/noul-comparison.wav \ --audio-roles reference comparison --output "$JEV_RUN_DIR/speaker.json" ``` ### Batch requests Use one request per JSONL line. The default Hugging Face CLI starts a worker for each request. In the [vLLM environment](../docs/vllm.md#installation), all requests in one invocation share a resident FunASR engine. Both backends return one record per input line in the original order. ```bash # Hugging Face qwen-audio-jev --batch examples/batch.jsonl --output "$JEV_RUN_DIR/batch.jsonl" ``` ```bash # FunASR vLLM qwen-audio-jev --backend vllm --batch examples/batch.jsonl --output "$JEV_RUN_DIR/batch-vllm.jsonl" ``` ### Python For `funasr.AutoModel`, see the [FunASR calling example](CALLING_EXAMPLES.md#funasr-automodel). For a resident FunASR engine, create one `JevVLLMModel` and use `infer()` for one request or `infer_batch()` for an ordered list. See the [vLLM SDK example](../docs/vllm.md#python-sdk). `JevModel()` reads `JEV_CHECKPOINT`. You can also pass `checkpoint="/path/to/jev-hf"` explicitly. ```python from qwen_audio_jev import JevModel result = JevModel().predict( task="score", question_id="quality", question="Rate the speech quality of audio_0.", criteria=["Very poor", "Poor", "Fair", "Good", "Excellent"], score_values=[1, 2, 3, 4, 5], audio=["examples/audios/score.wav"], ) print(result["answers"]["quality"]["mapped_score"]) ``` For Score, `score` is the expected zero-based level index. Supplying `score_values` adds `mapped_score` on the requested numerical scale, such as 1–5 MOS in this example. ## Streaming (Qwen-Audio-3.1-Jev-Tiny) Use a streaming-trained Qwen-Audio-3.1-Jev-Tiny checkpoint with its matching tokenizer. Set `JEV_CHECKPOINT` to that checkpoint before running these examples. One decision is produced per 160 ms of audio: 2,560 mono samples at 16 kHz. ### Process an audio file These examples process a complete file and return a sequence of decisions. The request JSON files already set `"streaming": true` and `"pad_final_chunk": true`. ```bash # VAD / Noul: speech activity probability at each step. qwen-audio-jev --variant qwen-audio-3.1-jev-tiny --input examples/streaming_vad.json \ --output "$JEV_RUN_DIR/stream-vad.json" # Rolling SNR / Score: ten levels over the preceding 1.28 seconds. qwen-audio-jev --variant qwen-audio-3.1-jev-tiny --input examples/streaming_snr.json \ --output "$JEV_RUN_DIR/stream-snr.json" ``` Replace the example audio, questions, and criteria for your checkpoint and task. Results are in `steps`; each step contains `time_seconds` and `response`. Score steps also include the argmax `score_level`. A partial final chunk is zero-padded only when `pad_final_chunk` is enabled; otherwise it raises an error. File inference evaluates all causal decision positions together and does not simulate audio arrival latency. ### Waveform packets in Python Use the Hugging Face environment for the `JevStreamingSession` packet API. The [vLLM streaming example](../docs/streaming.md#decode-an-audio-file) takes a complete audio file. This example feeds a bundled mono 16 kHz WAV in packets. For microphone or network input, replace `audio.blocks(...)` with your incoming waveform iterator. Each packet must be a one-dimensional float waveform at 16 kHz; packet sizes may vary. ```python import os import soundfile as sf import torch from qwen_audio_jev import JevForAudioDecision, JevProcessor, JevStreamingSession checkpoint = os.environ["JEV_CHECKPOINT"] processor = JevProcessor.from_pretrained(checkpoint, max_length=2048) model = JevForAudioDecision.from_pretrained( checkpoint, dtype=torch.bfloat16, device_map={"": "cuda:0"}, local_files_only=True, ) session = JevStreamingSession( model, processor, task="noul", question="Is human speech active now?", question_id="vad", criteria={"true": "Human speech is active now.", "false": "No human speech is active now."}, ) with sf.SoundFile("examples/audios/noul-reference.wav") as audio: for samples in audio.blocks(blocksize=2560, dtype="float32"): for step in session.push(samples): print(step["time_seconds"], step["response"]["answers"]["vad"]["noul"]) for step in session.finish(pad_final_chunk=True): print(step["time_seconds"], step["response"]["answers"]["vad"]["noul"]) ``` The model stays resident, and each session owns its audio history. Start a new session for a new recording or question, or before reaching the context limit. The current implementation recomputes the causal prefix at every step; it does not use a KV cache or guarantee real-time latency. See the [streaming guide](../docs/streaming.md) for the full input and output contract. ## Validate requests without inference Add `--validate-only` to a CLI request to check its format and local audio paths without loading weights or using a GPU: ```bash qwen-audio-jev --input examples/choice.json --validate-only ``` This check does not validate audio decoding or model predictions. See [Audio Sources and Attribution](AUDIO_ATTRIBUTION.md) for the bundled clips' datasets, sample identifiers, authors, and licenses.