# Calling Examples Run from the repository root. The `JevModel` patterns use the [Hugging Face environment](../docs/huggingface.md#dependencies). The [FunASR AutoModel example](#funasr-automodel) uses its linked FunASR environment. Set `JEV_CHECKPOINT` to a complete HF checkpoint. The WAV files in the basic examples are bundled in [audios/](audios/), with credits in [audio attribution](AUDIO_ATTRIBUTION.md). Copy one pattern, choose `language = "en"` or `"zh"`, then replace the audio, question and criteria as needed. Each selected prompt uses one language for its question and candidate text. Noul retains the fixed protocol keys `true` and `false`; their descriptions follow the question's language. ## Choice Supply a question and a list of candidate answers. The selected candidate and its probabilities are returned in the same names used in `criteria`. ```python from qwen_audio_jev import JevModel language = "zh" prompts = { "en": { "question": "Which sound is most prominent in audio_0?", "criteria": ["Rain", "Road traffic", "Music", "Human speech"], }, "zh": { "question": "audio_0 中最突出的声音是什么?", "criteria": ["下雨声", "道路交通声", "音乐", "说话声"], }, } result = JevModel().predict( task="choice", question_id="sound", audio=["examples/audios/noul-reference.wav"], streaming=False, **prompts[language], ) answer = result["answers"]["sound"] print(answer["choice"]) print(answer["probabilities"]) ``` The bundled input is a speech recording. For a different classification task, replace the question and the entire candidate list together. Chinese questions use Chinese candidate names, rather than English IDs with Chinese descriptions. Keep any application-ID mapping outside the request. ## Noul Describe a proposition and its true/false outcomes. This example uses two recordings for speaker verification; single-recording questions use one audio path. ```python from qwen_audio_jev import JevModel language = "zh" prompts = { "en": { "question": "Are audio_0 and audio_1 spoken by the same person?", "criteria": {"true": "Same speaker.", "false": "Different speakers."}, }, "zh": { "question": "audio_0 和 audio_1 是否由同一个人说话?", "criteria": {"true": "同一个说话人。", "false": "不同说话人。"}, }, } result = JevModel().predict( task="noul", question_id="same_speaker", audio=["examples/audios/noul-reference.wav", "examples/audios/noul-comparison.wav"], audio_roles=["reference", "comparison"], streaming=False, **prompts[language], ) print(result["answers"]["same_speaker"]["noul"]) ``` `noul` is the probability that the `true` outcome holds. The same calling form works for synthetic speech, turn completion, sarcasm, speech presence and overlap by replacing the proposition, outcome descriptions and audio inputs. ## Score Provide level descriptions ordered from lowest to highest. Set `score_values` explicitly to obtain a rating on the intended numerical scale. ```python from qwen_audio_jev import JevModel language = "zh" prompts = { "en": { "question": "Rate the overall speech quality of audio_0 from 1 to 5.", "criteria": ["Very poor", "Poor", "Fair", "Good", "Excellent"], }, "zh": { "question": "请对 audio_0 的整体语音质量进行 1 至 5 分评分。", "criteria": ["很差", "较差", "一般", "较好", "很好"], }, } result = JevModel().predict( task="score", question_id="quality", audio=["examples/audios/score.wav"], score_values=[1, 2, 3, 4, 5], streaming=False, **prompts[language], ) answer = result["answers"]["quality"] print(answer["mapped_score"]) ``` Here `mapped_score` is on the 1–5 scale; the native `score` is an expected level index in 0–4. When changing the rating scale, update the question, ordered criteria and `score_values` together. Pronunciation-related tasks retain their reference utterance verbatim; see the [task tutorials](TASKS.md) for those inputs. ### FunASR AutoModel Use `funasr.AutoModel` to rate speech quality in a FunASR application. Complete [FunASR installation and checkpoint setup](https://github.com/modelscope/FunASR/blob/694a931c2080a94f5f65b795f979899f64d8ded1/examples/qwen_audio_jev/README.md#prepare-the-environment-and-checkpoint) first. Set `JEV_SOURCE` to this repository's local directory and `JEV_CHECKPOINT` to a complete local Jev-Tiny checkpoint. The example loads the bundled [Score request](score.json). ```python import json import os from pathlib import Path from funasr import AutoModel examples = Path(os.environ["JEV_SOURCE"]).expanduser().resolve(strict=True) / "examples" request = json.loads((examples / "score.json").read_text(encoding="utf-8")) model = AutoModel( model="Qwen-Audio-Jev", jev_checkpoint=os.environ["JEV_CHECKPOINT"], device="cuda:0", disable_update=True, disable_pbar=True, ) row, = model.generate(input=request, key="quality-demo", jev_base_dir=str(examples)) print(json.dumps(row, ensure_ascii=False, allow_nan=False)) ``` Read `row["decision"]["answers"]["speech_quality"]["mapped_score"]` for the probability-weighted 1–5 rating. The separate `score` is the expected zero-based level index (0–4). To rate your own recording, set `request["audio"] = ["/path/to/recording.wav"]` before calling `generate()`. ## Streaming For these patterns, set `JEV_CHECKPOINT` to a matching streaming-trained Tiny checkpoint with its tokenizer. Inputs are mono 16 kHz audio. Each decision corresponds to 160 ms; `pad_final_chunk=True` permits a partial final chunk. ### Noul: current speech activity ```python from qwen_audio_jev import JevModel language = "zh" prompts = { "en": { "question": "Is human speech active now?", "criteria": {"true": "Human speech is active now.", "false": "No human speech is active now."}, }, "zh": { "question": "当前是否有人类语音活动?", "criteria": {"true": "当前有人类语音活动。", "false": "当前没有人类语音活动。"}, }, } result = JevModel(variant="tiny").predict( task="noul", question_id="vad", audio=["examples/audios/noul-reference.wav"], streaming=True, pad_final_chunk=True, **prompts[language], ) for step in result["steps"]: probability = step["response"]["answers"]["vad"]["noul"] print(step["time_seconds"], probability) ``` ### Score: rolling signal-to-noise ratio ```python from qwen_audio_jev import JevModel language = "zh" prompts = { "en": { "question": ( "Score speech SNR over the past 1.28 seconds in ten levels 0 to 9.\n" "SNR boundaries in dB, from 0 to 9: -10, -5, 0, 5, 10, 15, 20, 25, 30." ), "criteria": [f"SNR level {i}." for i in range(10)], }, "zh": { "question": ( "请将过去 1.28 秒的语音信噪比划分为 0 至 9 共十个等级。\n" "各等级的分界值(分贝)为:-10、-5、0、5、10、15、20、25、30。" ), "criteria": [f"信噪比等级 {i}" for i in range(10)], }, } result = JevModel(variant="tiny").predict( task="score", question_id="rolling_snr", audio=["examples/audios/tasks/9b82f5374786b74f7378e8d5.wav"], streaming=True, pad_final_chunk=True, **prompts[language], ) for step in result["steps"]: if step["time_seconds"] < 1.28: continue answer = step["response"]["answers"]["rolling_snr"] print(step["time_seconds"], answer["score"], step["score_level"]) ``` The SNR input is a bundled generated speech/noise mixture. `score` is the expected level index; `score_level` is the highest-probability level. These are level outputs, rather than a direct dB estimate. The example skips the initial 1.28-second warmup. Use the labelled task's masks when evaluating rolling windows. For incoming waveform packets, see the [resident streaming session](../docs/streaming.md#receive-waveform-chunks-with-a-resident-model). File-based streaming calls do not simulate audio-arrival latency. ## Composed calling example Reuse one recording across three non-streaming calls: Noul checks for regional Chinese dialect features, Choice selects a dialect family, and a second Choice selects a local label within Southwestern Mandarin. This is an application's annotation scheme; adapt the labels to your dataset. Use the Hugging Face environment described above and replace `my-data/dialect.wav` with your own recording. No verified Chongqing dialect recording is bundled for this example. Choose `language = "en"` or `"zh"` to switch the questions and criteria together. ```python import json from qwen_audio_jev import JevModel language = "zh" # "en" or "zh" audio = ["my-data/dialect.wav"] model = JevModel() prompts = { "en": { "gate": { "question": "Does audio_0 contain recognizable regional Chinese dialect features?", "criteria": { "true": "Recognizable regional Chinese dialect features are present.", "false": "Recognizable regional Chinese dialect features are absent.", }, }, "family": { "question": "Which label best describes audio_0 under this dialect annotation scheme?", "criteria": [ "Southwestern Mandarin", "Other Mandarin variety", "Cantonese", "Wu", "Min", "Other", "Insufficient evidence", ], }, "local": { "question": "Within Southwestern Mandarin, which local label best fits audio_0?", "criteria": [ "Chongqing variety", "Chengdu variety", "Guiyang variety", "Kunming variety", "Other", "Insufficient evidence", ], }, }, "zh": { "gate": { "question": "audio_0 是否具有可辨识的中文地域方言特征?", "criteria": { "true": "具有可辨识的中文地域方言特征。", "false": "不具有可辨识的中文地域方言特征。", }, }, "family": { "question": "按当前方言标注体系,哪个标签最符合 audio_0?", "criteria": [ "西南官话", "其他官话", "粤语", "吴语", "闽语", "其他", "证据不足", ], }, "local": { "question": "在西南官话分支内,audio_0 更符合哪个地方标签?", "criteria": [ "重庆话", "成都话", "贵阳话", "昆明话", "其他", "证据不足", ], }, }, } selected = prompts[language] stop_labels = { "en": {"Other", "Insufficient evidence"}, "zh": {"其他", "证据不足"}, }[language] def ask(task, stage): prompt = selected[stage] result = model.predict( task=task, question_id=stage, audio=audio, streaming=False, **prompt, ) answer = result["answers"][stage] # Print each actual request and model answer. print(json.dumps({ "stage": stage, "task": task, "question_id": stage, "audio": audio, "streaming": False, **prompt, "answer": answer, }, ensure_ascii=False, indent=2)) return answer def accepted(answer): name = answer["choice"] return ( name not in stop_labels and answer["probabilities"][name] >= 0.6 ) def annotate(): gate = ask("noul", "gate") if gate["noul"] < 0.8: return [] path = ["方言" if language == "zh" else "Dialect"] family = ask("choice", "family") if not accepted(family): return path path.append(family["choice"]) southwest = "西南官话" if language == "zh" else "Southwestern Mandarin" if family["choice"] != southwest: return path local = ask("choice", "local") if accepted(local): path.append(local["choice"]) return path print(json.dumps( {"label_path": annotate()}, ensure_ascii=False, indent=2, )) ``` The thresholds `0.8` (Noul) and `0.6` (Choice) are illustrative acceptance settings; calibrate them on validation data. A rejected Noul gate returns an empty path. An uncertain Choice or an `Other` label keeps the accepted parent path and stops further calls. Other accepted families, such as Cantonese, also stop after the family stage because this example only defines local candidates for Southwestern Mandarin. Each visited stage prints its question, criteria and actual model answer. The final JSON object contains the accepted label path. Illustrative output for `language = "zh"` (not a measured inference result): ```json {"label_path": ["方言", "西南官话", "重庆话"]} ``` With `language = "en"`, the corresponding labels are `Dialect`, `Southwestern Mandarin` and `Chongqing variety`. Evaluate recognition accuracy on labelled recordings before using this annotation scheme. ## Command-line calls The commands below default to Hugging Face. In the [FunASR vLLM environment](../docs/vllm.md#installation), add `--backend vllm` to use the same request fields with that backend. The bundled JSON requests introduce the same interfaces: ```bash qwen-audio-jev --input examples/choice.json qwen-audio-jev --input examples/noul.json qwen-audio-jev --input examples/score.json # Use the streaming-trained Tiny checkpoint for these calls. qwen-audio-jev --variant tiny --input examples/streaming_vad.json qwen-audio-jev --variant tiny --input examples/streaming_snr.json ``` Pass the question and criteria directly to try the corresponding Chinese patterns: ```bash # Choice qwen-audio-jev --task choice --question-id sound \ --question 'audio_0 中最突出的声音是什么?' \ --criteria '["下雨声","道路交通声","音乐","说话声"]' \ --audio examples/audios/noul-reference.wav # Noul qwen-audio-jev --task noul --question-id same_speaker \ --question 'audio_0 和 audio_1 是否由同一个人说话?' \ --criteria '{"true":"同一个说话人。","false":"不同说话人。"}' \ --audio examples/audios/noul-reference.wav examples/audios/noul-comparison.wav \ --audio-roles reference comparison # Score qwen-audio-jev --task score --question-id quality \ --question '请对 audio_0 的整体语音质量进行 1 至 5 分评分。' \ --criteria '["很差","较差","一般","较好","很好"]' \ --score-values '[1,2,3,4,5]' --audio examples/audios/score.wav # Streaming Noul qwen-audio-jev --variant tiny --streaming --pad-final-chunk --task noul --question-id vad \ --question '当前是否有人类语音活动?' \ --criteria '{"true":"当前有人类语音活动。","false":"当前没有人类语音活动。"}' \ --audio examples/audios/noul-reference.wav # Streaming Score qwen-audio-jev --variant tiny --streaming --pad-final-chunk --task score --question-id rolling_snr \ --question '请将过去 1.28 秒的语音信噪比划分为 0 至 9 共十个等级。各等级的分界值(分贝)为:-10、-5、0、5、10、15、20、25、30。' \ --criteria '["信噪比等级 0","信噪比等级 1","信噪比等级 2","信噪比等级 3","信噪比等级 4","信噪比等级 5","信噪比等级 6","信噪比等级 7","信噪比等级 8","信噪比等级 9"]' \ --audio examples/audios/tasks/9b82f5374786b74f7378e8d5.wav ``` Add `--validate-only` to check request structure and local files without model execution. For example: ```bash qwen-audio-jev --input examples/noul.json --validate-only ``` ## More task examples The [31 task tutorials](TASKS.md) provide audio, complete requests and five labelled records per task. Select a task and sample: ```bash python examples/task_demo.py --task language --sample 1 --checkpoint "$JEV_CHECKPOINT" ``` Use the helper's existing `--question` and `--criteria` options to supply either prompt language. For example, these calls use the same audio and candidate order: ```bash python examples/task_demo.py --task language --sample 1 \ --question 'Which language is spoken in audio_0?' \ --criteria '["English","Mandarin Chinese","Japanese"]' \ --checkpoint "$JEV_CHECKPOINT" python examples/task_demo.py --task language --sample 1 \ --question 'audio_0 中说的是哪种语言?' \ --criteria '["英语","普通话","日语"]' \ --checkpoint "$JEV_CHECKPOINT" ``` The task directories retain their original complete requests and labelled records. Keep any application-ID mapping outside the model request when changing candidate names. The examples above show how to call the interfaces; recognition accuracy for newly supplied questions or recordings must be measured separately.