mirror of
https://github.com/snakers4/silero-vad.git
synced 2026-02-05 01:49:22 +08:00
Compare commits
12 Commits
adamnsandl
...
v5.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84768cefdf | ||
|
|
6de3660f25 | ||
|
|
d9a6941852 | ||
|
|
dfdc9a484e | ||
|
|
f2e3a23d96 | ||
|
|
2b97f61160 | ||
|
|
657dac8736 | ||
|
|
412a478e29 | ||
|
|
9adf6d2192 | ||
|
|
8a2a73c14f | ||
|
|
3e0305559d | ||
|
|
f0d880d79c |
42
README.md
42
README.md
@@ -25,6 +25,34 @@ https://user-images.githubusercontent.com/36505480/144874384-95f80f6d-a4f1-42cc-
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
<h2 align="center">Fast start</h2>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
**Using pip**:
|
||||||
|
`pip install silero-vad`
|
||||||
|
|
||||||
|
```python3
|
||||||
|
from silero_vad import load_silero_vad, read_audio, get_speech_timestamps
|
||||||
|
model = load_silero_vad()
|
||||||
|
wav = read_audio('path_to_audio_file') # backend (sox, soundfile, or ffmpeg) required!
|
||||||
|
speech_timestamps = get_speech_timestamps(wav, model)
|
||||||
|
```
|
||||||
|
|
||||||
|
**Using torch.hub**:
|
||||||
|
```python3
|
||||||
|
import torch
|
||||||
|
torch.set_num_threads(1)
|
||||||
|
|
||||||
|
model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad')
|
||||||
|
(get_speech_timestamps, _, read_audio, _, _) = utils
|
||||||
|
|
||||||
|
wav = read_audio('path_to_audio_file') # backend (sox, soundfile, or ffmpeg) required!
|
||||||
|
speech_timestamps = get_speech_timestamps(wav, model)
|
||||||
|
```
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
<h2 align="center">Key Features</h2>
|
<h2 align="center">Key Features</h2>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
@@ -57,21 +85,7 @@ https://user-images.githubusercontent.com/36505480/144874384-95f80f6d-a4f1-42cc-
|
|||||||
Published under permissive license (MIT) Silero VAD has zero strings attached - no telemetry, no keys, no registration, no built-in expiration, no keys or vendor lock.
|
Published under permissive license (MIT) Silero VAD has zero strings attached - no telemetry, no keys, no registration, no built-in expiration, no keys or vendor lock.
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<h2 align="center">Fast start</h2>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
```python3
|
|
||||||
import torch
|
|
||||||
torch.set_num_threads(1)
|
|
||||||
|
|
||||||
model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad')
|
|
||||||
(get_speech_timestamps, _, read_audio, _, _) = utils
|
|
||||||
|
|
||||||
wav = read_audio('path_to_audio_file')
|
|
||||||
speech_timestamps = get_speech_timestamps(wav, model)
|
|
||||||
```
|
|
||||||
|
|
||||||
<br/>
|
|
||||||
<h2 align="center">Typical Use Cases</h2>
|
<h2 align="center">Typical Use Cases</h2>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
{"59": "mg, Malagasy", "76": "tk, Turkmen", "20": "lb, Luxembourgish, Letzeburgesch", "62": "or, Oriya", "30": "en, English", "26": "oc, Occitan", "69": "no, Norwegian", "77": "sr, Serbian", "90": "bs, Bosnian", "71": "el, Greek, Modern (1453\u2013)", "15": "az, Azerbaijani", "12": "lo, Lao", "85": "zh-HK, Chinese", "79": "cs, Czech", "43": "sv, Swedish", "37": "mn, Mongolian", "32": "fi, Finnish", "51": "tg, Tajik", "46": "am, Amharic", "17": "nn, Norwegian Nynorsk", "40": "ja, Japanese", "8": "it, Italian", "21": "ha, Hausa", "11": "as, Assamese", "29": "fa, Persian", "82": "bn, Bengali", "54": "mk, Macedonian", "31": "sw, Swahili", "45": "vi, Vietnamese", "41": "ur, Urdu", "74": "bo, Tibetan", "4": "hi, Hindi", "86": "mr, Marathi", "3": "fy-NL, Western Frisian", "65": "sk, Slovak", "2": "ln, Lingala", "92": "gl, Galician", "53": "sn, Shona", "87": "su, Sundanese", "35": "tt, Tatar", "93": "kn, Kannada", "6": "yo, Yoruba", "27": "ps, Pashto, Pushto", "34": "hy, Armenian", "25": "pa-IN, Punjabi, Panjabi", "23": "nl, Dutch, Flemish", "48": "th, Thai", "73": "mt, Maltese", "55": "ar, Arabic", "89": "ba, Bashkir", "78": "bg, Bulgarian", "42": "yi, Yiddish", "5": "ru, Russian", "84": "sv-SE, Swedish", "80": "tr, Turkish", "33": "sq, Albanian", "38": "kk, Kazakh", "50": "pl, Polish", "9": "hr, Croatian", "66": "ky, Kirghiz, Kyrgyz", "49": "hu, Hungarian", "10": "si, Sinhala, Sinhalese", "56": "la, Latin", "75": "de, German", "14": "ko, Korean", "22": "id, Indonesian", "47": "sl, Slovenian", "57": "be, Belarusian", "36": "ta, Tamil", "7": "da, Danish", "91": "sd, Sindhi", "28": "et, Estonian", "63": "pt, Portuguese", "60": "ne, Nepali", "94": "zh-TW, Chinese", "18": "zh-CN, Chinese", "88": "rw, Kinyarwanda", "19": "es, Spanish, Castilian", "39": "ht, Haitian, Haitian Creole", "64": "tl, Tagalog", "83": "ms, Malay", "70": "ro, Romanian, Moldavian, Moldovan", "68": "pa, Punjabi, Panjabi", "52": "uz, Uzbek", "58": "km, Central Khmer", "67": "my, Burmese", "0": "fr, French", "24": "af, Afrikaans", "16": "gu, Gujarati", "81": "so, Somali", "13": "uk, Ukrainian", "44": "ca, Catalan, Valencian", "72": "ml, Malayalam", "61": "te, Telugu", "1": "zh, Chinese"}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"0": ["Afrikaans", "Dutch, Flemish", "Western Frisian"], "1": ["Turkish", "Azerbaijani"], "2": ["Russian", "Slovak", "Ukrainian", "Czech", "Polish", "Belarusian"], "3": ["Bulgarian", "Macedonian", "Serbian", "Croatian", "Bosnian", "Slovenian"], "4": ["Norwegian Nynorsk", "Swedish", "Danish", "Norwegian"], "5": ["English"], "6": ["Finnish", "Estonian"], "7": ["Yiddish", "Luxembourgish, Letzeburgesch", "German"], "8": ["Spanish", "Occitan", "Portuguese", "Catalan, Valencian", "Galician", "Spanish, Castilian", "Italian"], "9": ["Maltese", "Arabic"], "10": ["Marathi"], "11": ["Hindi", "Urdu"], "12": ["Lao", "Thai"], "13": ["Malay", "Indonesian"], "14": ["Romanian, Moldavian, Moldovan"], "15": ["Tagalog"], "16": ["Tajik", "Persian"], "17": ["Kazakh", "Uzbek", "Kirghiz, Kyrgyz"], "18": ["Kinyarwanda"], "19": ["Tatar", "Bashkir"], "20": ["French"], "21": ["Chinese"], "22": ["Lingala"], "23": ["Yoruba"], "24": ["Sinhala, Sinhalese"], "25": ["Assamese"], "26": ["Korean"], "27": ["Gujarati"], "28": ["Hausa"], "29": ["Punjabi, Panjabi"], "30": ["Pashto, Pushto"], "31": ["Swahili"], "32": ["Albanian"], "33": ["Armenian"], "34": ["Mongolian"], "35": ["Tamil"], "36": ["Haitian, Haitian Creole"], "37": ["Japanese"], "38": ["Vietnamese"], "39": ["Amharic"], "40": ["Hungarian"], "41": ["Shona"], "42": ["Latin"], "43": ["Central Khmer"], "44": ["Malagasy"], "45": ["Nepali"], "46": ["Telugu"], "47": ["Oriya"], "48": ["Burmese"], "49": ["Greek, Modern (1453\u2013)"], "50": ["Malayalam"], "51": ["Tibetan"], "52": ["Turkmen"], "53": ["Somali"], "54": ["Bengali"], "55": ["Sundanese"], "56": ["Sindhi"], "57": ["Kannada"]}
|
|
||||||
21
hubconf.py
21
hubconf.py
@@ -1,16 +1,15 @@
|
|||||||
dependencies = ['torch', 'torchaudio']
|
dependencies = ['torch', 'torchaudio']
|
||||||
import torch
|
import torch
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
from utils_vad import (init_jit_model,
|
import sys
|
||||||
get_speech_timestamps,
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
||||||
save_audio,
|
from silero_vad.utils_vad import (init_jit_model,
|
||||||
read_audio,
|
get_speech_timestamps,
|
||||||
VADIterator,
|
save_audio,
|
||||||
collect_chunks,
|
read_audio,
|
||||||
drop_chunks,
|
VADIterator,
|
||||||
Validator,
|
collect_chunks,
|
||||||
OnnxWrapper)
|
OnnxWrapper)
|
||||||
|
|
||||||
|
|
||||||
def versiontuple(v):
|
def versiontuple(v):
|
||||||
@@ -36,7 +35,7 @@ def silero_vad(onnx=False, force_onnx_cpu=False):
|
|||||||
if versiontuple(installed_version) < versiontuple(supported_version):
|
if versiontuple(installed_version) < versiontuple(supported_version):
|
||||||
raise Exception(f'Please install torch {supported_version} or greater ({installed_version} installed)')
|
raise Exception(f'Please install torch {supported_version} or greater ({installed_version} installed)')
|
||||||
|
|
||||||
model_dir = os.path.join(os.path.dirname(__file__), 'files')
|
model_dir = os.path.join(os.path.dirname(__file__), 'src', 'silero_vad', 'data')
|
||||||
if onnx:
|
if onnx:
|
||||||
model = OnnxWrapper(os.path.join(model_dir, 'silero_vad.onnx'), force_onnx_cpu)
|
model = OnnxWrapper(os.path.join(model_dir, 'silero_vad.onnx'), force_onnx_cpu)
|
||||||
else:
|
else:
|
||||||
|
|||||||
35
pyproject.toml
Normal file
35
pyproject.toml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
[project]
|
||||||
|
name = "silero-vad"
|
||||||
|
version = "5.1"
|
||||||
|
authors = [
|
||||||
|
{name="Silero Team", email="hello@silero.ai"},
|
||||||
|
]
|
||||||
|
description = "Voice Activity Detector (VAD) by Silero"
|
||||||
|
readme = "README.md"
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 5 - Production/Stable",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Intended Audience :: Science/Research",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
||||||
|
"Topic :: Scientific/Engineering",
|
||||||
|
]
|
||||||
|
dependencies = [
|
||||||
|
"torch>=1.12.0",
|
||||||
|
"torchaudio>=0.12.0",
|
||||||
|
"onnxruntime>=1.18.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Homepage = "https://github.com/snakers4/silero-vad"
|
||||||
|
Issues = "https://github.com/snakers4/silero-vad/issues"
|
||||||
@@ -43,20 +43,30 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
"USE_PIP = True # download model using pip package or torch.hub\n",
|
||||||
"USE_ONNX = False # change this to True if you want to test onnx model\n",
|
"USE_ONNX = False # change this to True if you want to test onnx model\n",
|
||||||
"if USE_ONNX:\n",
|
"if USE_ONNX:\n",
|
||||||
" !pip install -q onnxruntime\n",
|
" !pip install -q onnxruntime\n",
|
||||||
|
"if USE_PIP:\n",
|
||||||
|
" !pip install -q silero-vad\n",
|
||||||
|
" from silero_vad import (load_silero_vad,\n",
|
||||||
|
" read_audio,\n",
|
||||||
|
" get_speech_timestamps,\n",
|
||||||
|
" save_audio,\n",
|
||||||
|
" VADIterator,\n",
|
||||||
|
" collect_chunks)\n",
|
||||||
|
" model = load_silero_vad(onnx=USE_ONNX)\n",
|
||||||
|
"else:\n",
|
||||||
|
" model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad',\n",
|
||||||
|
" model='silero_vad',\n",
|
||||||
|
" force_reload=True,\n",
|
||||||
|
" onnx=USE_ONNX)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad',\n",
|
" (get_speech_timestamps,\n",
|
||||||
" model='silero_vad',\n",
|
" save_audio,\n",
|
||||||
" force_reload=True,\n",
|
" read_audio,\n",
|
||||||
" onnx=USE_ONNX)\n",
|
" VADIterator,\n",
|
||||||
"\n",
|
" collect_chunks) = utils"
|
||||||
"(get_speech_timestamps,\n",
|
|
||||||
" save_audio,\n",
|
|
||||||
" read_audio,\n",
|
|
||||||
" VADIterator,\n",
|
|
||||||
" collect_chunks) = utils"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
12
src/silero_vad/__init__.py
Normal file
12
src/silero_vad/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from importlib.metadata import version
|
||||||
|
try:
|
||||||
|
__version__ = version(__name__)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
from silero_vad.model import load_silero_vad
|
||||||
|
from silero_vad.utils_vad import (get_speech_timestamps,
|
||||||
|
save_audio,
|
||||||
|
read_audio,
|
||||||
|
VADIterator,
|
||||||
|
collect_chunks)
|
||||||
0
src/silero_vad/data/__init__.py
Normal file
0
src/silero_vad/data/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
25
src/silero_vad/model.py
Normal file
25
src/silero_vad/model.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
from .utils_vad import init_jit_model, OnnxWrapper
|
||||||
|
import torch
|
||||||
|
torch.set_num_threads(1)
|
||||||
|
|
||||||
|
def load_silero_vad(onnx=False):
|
||||||
|
model_name = 'silero_vad.onnx' if onnx else 'silero_vad.jit'
|
||||||
|
package_path = "silero_vad.data"
|
||||||
|
|
||||||
|
try:
|
||||||
|
import importlib_resources as impresources
|
||||||
|
model_file_path = str(impresources.files(package_path).joinpath(model_name))
|
||||||
|
except:
|
||||||
|
from importlib import resources as impresources
|
||||||
|
try:
|
||||||
|
with impresources.path(package_path, model_name) as f:
|
||||||
|
model_file_path = f
|
||||||
|
except:
|
||||||
|
model_file_path = str(impresources.files(package_path).joinpath(model_name))
|
||||||
|
|
||||||
|
if onnx:
|
||||||
|
model = OnnxWrapper(model_file_path, force_onnx_cpu=True)
|
||||||
|
else:
|
||||||
|
model = init_jit_model(model_file_path)
|
||||||
|
|
||||||
|
return model
|
||||||
@@ -132,18 +132,19 @@ class Validator():
|
|||||||
|
|
||||||
def read_audio(path: str,
|
def read_audio(path: str,
|
||||||
sampling_rate: int = 16000):
|
sampling_rate: int = 16000):
|
||||||
|
list_backends = torchaudio.list_audio_backends()
|
||||||
|
|
||||||
|
assert len(list_backends) > 0, 'The list of available backends is empty, please install backend manually. \
|
||||||
|
\n Recommendations: \n \tSox (UNIX OS) \n \tSoundfile (Windows OS, UNIX OS) \n \tffmpeg (Windows OS, UNIX OS)'
|
||||||
|
|
||||||
sox_backends = set(['sox', 'sox_io'])
|
try:
|
||||||
audio_backends = torchaudio.list_audio_backends()
|
|
||||||
|
|
||||||
if len(sox_backends.intersection(audio_backends)) > 0:
|
|
||||||
effects = [
|
effects = [
|
||||||
['channels', '1'],
|
['channels', '1'],
|
||||||
['rate', str(sampling_rate)]
|
['rate', str(sampling_rate)]
|
||||||
]
|
]
|
||||||
|
|
||||||
wav, sr = torchaudio.sox_effects.apply_effects_file(path, effects=effects)
|
wav, sr = torchaudio.sox_effects.apply_effects_file(path, effects=effects)
|
||||||
else:
|
except:
|
||||||
wav, sr = torchaudio.load(path)
|
wav, sr = torchaudio.load(path)
|
||||||
|
|
||||||
if wav.size(0) > 1:
|
if wav.size(0) > 1:
|
||||||
Reference in New Issue
Block a user