Views
No views yet
| 版本 | 大小 | 阈值 | F1 | FAR | FRR | RTF |
|---|---|---|---|---|---|---|
| FP32 (默认) | 13MB | 0.52 | 89.47% | 5.64% | 2.30% | 0.0185 |
| INT8 | 5MB | 0.46 | 89.01% | 5.96% | 2.30% | 0.0140 |
pip install -r requirements.txtpip install sherpa-onnx sounddevice soundfile numpy1cd examples
2python realtime_detection.py1from inference import load_model
2
3# 加载FP32模型(默认)
4detector = load_model()
5
6# 或加载INT8模型(更小更快)
7detector = load_model(variant="int8")
8
9# 检测音频文件
10result = detector.detect("path/to/audio.wav")
11print(f"检测到关键词: {result['detected']}")
12print(f"关键词: {result['keyword']}")1import numpy as np
2from inference import load_model
3
4detector = load_model()
5stream = detector.create_stream()
6
7# 模拟流式音频输入
8chunk_size = 1600 # 100ms @ 16kHz
9audio_data = np.random.randn(chunk_size).astype(np.float32)
10
11stream.accept_waveform(16000, audio_data.tolist())
12while detector._kws.is_ready(stream):
13 detector._kws.decode_stream(stream)
14
15result = detector._kws.get_result(stream)
16print(result)nihao-zhenzhen-kws/
├── model/ # FP32模型 (13MB)
│ ├── encoder.onnx
│ ├── decoder.onnx
│ ├── joiner.onnx
│ ├── tokens.txt
│ └── keywords.txt
├── model_int8/ # INT8模型 (5MB)
│ ├── encoder.onnx
│ ├── decoder.onnx
│ ├── joiner.onnx
│ ├── tokens.txt
│ └── keywords.txt
├── examples/
│ └── realtime_detection.py
├── config.json
├── inference.py
├── requirements.txt
└── README.md