Python实时VAD检测库,基于Silero VAD模型
Project description
realtime-vad-python
Python实时语音活动检测(VAD)库,基于Silero VAD模型实现。此库可以实时检测音频流中的语音片段,适用于实时语音识别、在线会议等场景。
特性
- 实时处理音频流
- 低延迟检测(约32ms延迟)
- 可自定义语音检测阈值和参数
- 支持内置模型,无需手动下载
- 多线程设计,不阻塞主线程
安装
pip install realtime-vad-python
使用方法
简单示例
import time
import pyaudio
from realtime_vad import RealTimeVadDetector
# 创建回调函数
def on_speech_data(audio_data, duration_ms):
print(f"检测到语音片段,时长: {duration_ms}毫秒")
def on_start_speaking():
print("检测到开始说话...")
# 初始化VAD检测器(使用内置模型)
detector = RealTimeVadDetector(
on_speech_data=on_speech_data,
on_start_speaking=on_start_speaking,
use_default_model=True # 使用默认内置模型
)
# 启动VAD检测
detector.start_detect()
# 设置PyAudio进行麦克风录音
p = pyaudio.PyAudio()
stream = p.open(
format=pyaudio.paInt16,
channels=1,
rate=16000,
input=True,
frames_per_buffer=512
)
try:
while True:
# 读取音频数据
data = stream.read(512)
# 将数据送入VAD检测器
detector.put_pcm_data(data)
time.sleep(0.01)
except KeyboardInterrupt:
pass
finally:
# 清理资源
stream.stop_stream()
stream.close()
p.terminate()
detector.close()
自定义配置
可以通过 VadConfig 类自定义VAD参数:
from realtime_vad import RealTimeVadDetector, VadConfig
# 创建自定义配置
config = VadConfig(
positive_speech_threshold=0.8, # 语音检测的正阈值
negative_speech_threshold=0.3, # 语音检测的负阈值
redemption_frames=6, # 6帧无语音才判定说话结束
min_speech_frames=3, # 最少3帧才算有效语音
frame_samples=512, # 每帧样本数(32ms@16kHz)
vad_interval=0.032 # VAD检测间隔
)
# 初始化VAD检测器
detector = RealTimeVadDetector(
config=config,
on_speech_data=on_speech_data,
on_start_speaking=on_start_speaking
)
模型选项
该库提供了三种使用模型的方式:
-
使用内置模型(默认):
detector = RealTimeVadDetector(use_default_model=True)
-
指定自定义模型路径:
detector = RealTimeVadDetector(model_path="/path/to/your/silero_vad.jit")
-
从Torch Hub下载模型:
detector = RealTimeVadDetector(use_default_model=False)
开发说明
如果您想参与开发或修改源码,首先克隆仓库:
git clone https://github.com/your-username/realtime-vad-python.git
cd realtime-vad-python
下载并保存模型
如果您需要更新内置模型,可以使用提供的脚本:
python download_model.py
许可证
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file realtime_vad_python-0.1.1.tar.gz.
File metadata
- Download URL: realtime_vad_python-0.1.1.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce15bb5b38ce3f094ea9262c21970f1ec92f65287bd4fbd88f8e22407c260cda
|
|
| MD5 |
205cd973d2f55ea9e54b3d2ef39447d2
|
|
| BLAKE2b-256 |
c3d2ca8f14133739ac0bf8ca0f26d4c8da392c771f13e65fcfc981980a8071bc
|
Provenance
The following attestation bundles were made for realtime_vad_python-0.1.1.tar.gz:
Publisher:
realease.yml on Mereithhh/realtime-vad-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
realtime_vad_python-0.1.1.tar.gz -
Subject digest:
ce15bb5b38ce3f094ea9262c21970f1ec92f65287bd4fbd88f8e22407c260cda - Sigstore transparency entry: 204571883
- Sigstore integration time:
-
Permalink:
Mereithhh/realtime-vad-python@bffc6c4db3ab248e359a601202c5874c7e378e9f -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Mereithhh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
realease.yml@bffc6c4db3ab248e359a601202c5874c7e378e9f -
Trigger Event:
push
-
Statement type:
File details
Details for the file realtime_vad_python-0.1.1-py3-none-any.whl.
File metadata
- Download URL: realtime_vad_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f491270e12c82c7273e727098c38c621b5593b3b03fe02ca464d96100e4a1d86
|
|
| MD5 |
ea4390dbbcf279588b172b70a4e264b6
|
|
| BLAKE2b-256 |
835b1913a3b9eede1d5e88155250e644c5f45803e1e80bc8fd1a8ab07d4c36ea
|
Provenance
The following attestation bundles were made for realtime_vad_python-0.1.1-py3-none-any.whl:
Publisher:
realease.yml on Mereithhh/realtime-vad-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
realtime_vad_python-0.1.1-py3-none-any.whl -
Subject digest:
f491270e12c82c7273e727098c38c621b5593b3b03fe02ca464d96100e4a1d86 - Sigstore transparency entry: 204571884
- Sigstore integration time:
-
Permalink:
Mereithhh/realtime-vad-python@bffc6c4db3ab248e359a601202c5874c7e378e9f -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Mereithhh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
realease.yml@bffc6c4db3ab248e359a601202c5874c7e378e9f -
Trigger Event:
push
-
Statement type: