ONNX exports of the
Qwen3-Voice-Embedding-12Hz-0.6B ECAPA-TDNN speaker encoder. Produces
1024-dimensional x-vector speaker embeddings from audio.
1import numpy as np
2import onnxruntime as ort
3import librosa
4
5# Load model
6session = ort.InferenceSession("speaker_encoder_fp32.onnx")
7
8# Compute mel spectrogram (must match training preprocessing)
9audio, sr = librosa.load("audio.wav", sr=24000, mono=True)
10mel = librosa.feature.melspectrogram(
11 y=audio, sr=24000, n_fft=1024, hop_length=256,
12 n_mels=128, fmin=0, fmax=12000,
13)
14mel = np.log(np.clip(mel, a_min=1e-5, a_max=None))
15mel = mel.T[np.newaxis, ...] # (1, time, 128)
16
17# Run inference
18embedding = session.run(None, {"mel_spectrogram": mel.astype(np.float32)})[0]
19# embedding shape: (1, 1024)
1import * as ort from "onnxruntime-web";
2
3const session = await ort.InferenceSession.create("speaker_encoder_fp16.onnx");
4
5// mel: Float32Array of shape [1, time_steps, 128]
6const tensor = new ort.Tensor("float32", mel, [1, timeSteps, 128]);
7const results = await session.run({ mel_spectrogram: tensor });
8const embedding = results.speaker_embedding.data; // Float32Array(1024)
The time axis is dynamic — any length mel spectrogram is accepted.
Exported with
torch.onnx.export (opset 18) from the
standalone PyTorch model. Verified against PyTorch output (cosine similarity > 0.9999).
The export script is available at:
scripts/export_onnx.py
1@article{qwen3-tts,
2 title={Qwen3-TTS Technical Report},
3 author={Hu, Hangrui and Zhu, Xinfa and He, Ting and Guo, Dake and Zhang, Bin and Wang, Xiong and Guo, Zhifang and Jiang, Ziyue and Hao, Hongkun and Guo, Zishan and Zhang, Xinyu and Zhang, Pei and Yang, Baosong and Xu, Jin and Zhou, Jingren and Lin, Junyang},
4 journal={arXiv preprint arXiv:2601.15621},
5 year={2026}
6}
1@article{ecapa-tdnn,
2 title={ECAPA-TDNN: Emphasized Channel Attention, Propagation and Aggregation in TDNN Based Speaker Verification},
3 author={Desplanques, Brecht and Thienpondt, Jenthe and Demuynck, Kris},
4 journal={Proc. Interspeech},
5 year={2020}
6}