Speaker separation model for splitting overlapping speech into individual speaker streams. Exported from
SpeechBrain 's pretrained SepFormer on WSJ0-2Mix.
1 import onnxruntime as ort
2 import numpy as np
3
4 # Use int8 model (recommended)
5 sess = ort . InferenceSession ( "conv_tasnet_libri2mix_int8.onnx" )
6
7 # Input: mono waveform at 8kHz
8 mixture = np . random . randn ( 1 , 8000 ) . astype ( np . float32 ) # 1 second
9 separated = sess . run ( None , { "mixture" : mixture } ) [ 0 ]
10
11 # separated.shape = (1, 2, 8000) — two speaker sources
12 source_1 = separated [ 0 , 0 , : ]
13 source_2 = separated [ 0 , 1 , : ]
1 use ort :: session :: Session ;
2 use ndarray :: Array2 ;
3
4 let session = Session :: builder ( ) ? . commit_from_file ( "conv_tasnet_libri2mix_int8.onnx" ) ? ;
5 let input = Array2 :: < f32 > :: zeros ( ( 1 , 8000 ) ) ; // 1s at 8kHz
6 let outputs = session . run ( ort :: inputs! [ input . view ( ) ] ) ? ;
7 // outputs[0] shape: [1, 2, 8000]
System audio (16kHz) → overlap detected?
├─ NO → normal single-speaker path
└─ YES → resample 16→8kHz → SepFormer → 2 sources → resample 8→16kHz
→ WeSpeaker embedding per source → cluster → per-speaker decode
1 pip install speechbrain torch onnx onnxruntime
2
3 # Export FP32 model
4 python scripts/export_conv_tasnet.py
5
6 # Quantize to int8
7 python -c "
8 from onnxruntime.quantization import quantize_dynamic, QuantType
9 quantize_dynamic(
10 'conv_tasnet_libri2mix.onnx',
11 'conv_tasnet_libri2mix_int8.onnx',
12 weight_type=QuantType.QUInt8,
13 op_types_to_quantize=['MatMul'],
14 )
15 "
The SepFormer model weights are from SpeechBrain (Apache 2.0). WSJ0-2Mix data is from the Wall Street Journal corpus (LDC license).