Skip to content

Commit 84768ce

Browse files
authored
Merge pull request #493 from snakers4/adamnsandle
Adamnsandle
2 parents 2b97f61 + 6de3660 commit 84768ce

File tree

12 files changed

+136
-42
lines changed

12 files changed

+136
-42
lines changed

README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,34 @@ https://user-images.githubusercontent.com/36505480/144874384-95f80f6d-a4f1-42cc-
2525
</details>
2626

2727
<br/>
28+
29+
<h2 align="center">Fast start</h2>
30+
<br/>
31+
32+
**Using pip**:
33+
`pip install silero-vad`
34+
35+
```python3
36+
from silero_vad import load_silero_vad, read_audio, get_speech_timestamps
37+
model = load_silero_vad()
38+
wav = read_audio('path_to_audio_file') # backend (sox, soundfile, or ffmpeg) required!
39+
speech_timestamps = get_speech_timestamps(wav, model)
40+
```
41+
42+
**Using torch.hub**:
43+
```python3
44+
import torch
45+
torch.set_num_threads(1)
46+
47+
model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad')
48+
(get_speech_timestamps, _, read_audio, _, _) = utils
49+
50+
wav = read_audio('path_to_audio_file') # backend (sox, soundfile, or ffmpeg) required!
51+
speech_timestamps = get_speech_timestamps(wav, model)
52+
```
53+
54+
<br/>
55+
2856
<h2 align="center">Key Features</h2>
2957
<br/>
3058

@@ -57,21 +85,7 @@ https://user-images.githubusercontent.com/36505480/144874384-95f80f6d-a4f1-42cc-
5785
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.
5886

5987
<br/>
60-
<h2 align="center">Fast start</h2>
61-
<br/>
6288

63-
```python3
64-
import torch
65-
torch.set_num_threads(1)
66-
67-
model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad')
68-
(get_speech_timestamps, _, read_audio, _, _) = utils
69-
70-
wav = read_audio('path_to_audio_file')
71-
speech_timestamps = get_speech_timestamps(wav, model)
72-
```
73-
74-
<br/>
7589
<h2 align="center">Typical Use Cases</h2>
7690
<br/>
7791

files/lang_dict_95.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

files/lang_group_dict_95.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

hubconf.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
dependencies = ['torch', 'torchaudio']
22
import torch
3-
import json
43
import os
5-
from utils_vad import (init_jit_model,
6-
get_speech_timestamps,
7-
save_audio,
8-
read_audio,
9-
VADIterator,
10-
collect_chunks,
11-
drop_chunks,
12-
Validator,
13-
OnnxWrapper)
4+
import sys
5+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
6+
from silero_vad.utils_vad import (init_jit_model,
7+
get_speech_timestamps,
8+
save_audio,
9+
read_audio,
10+
VADIterator,
11+
collect_chunks,
12+
OnnxWrapper)
1413

1514

1615
def versiontuple(v):
@@ -36,7 +35,7 @@ def silero_vad(onnx=False, force_onnx_cpu=False):
3635
if versiontuple(installed_version) < versiontuple(supported_version):
3736
raise Exception(f'Please install torch {supported_version} or greater ({installed_version} installed)')
3837

39-
model_dir = os.path.join(os.path.dirname(__file__), 'files')
38+
model_dir = os.path.join(os.path.dirname(__file__), 'src', 'silero_vad', 'data')
4039
if onnx:
4140
model = OnnxWrapper(os.path.join(model_dir, 'silero_vad.onnx'), force_onnx_cpu)
4241
else:

pyproject.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
[project]
5+
name = "silero-vad"
6+
version = "5.1"
7+
authors = [
8+
{name="Silero Team", email="[email protected]"},
9+
]
10+
description = "Voice Activity Detector (VAD) by Silero"
11+
readme = "README.md"
12+
requires-python = ">=3.8"
13+
classifiers = [
14+
"Development Status :: 5 - Production/Stable",
15+
"License :: OSI Approved :: MIT License",
16+
"Operating System :: OS Independent",
17+
"Intended Audience :: Science/Research",
18+
"Intended Audience :: Developers",
19+
"Programming Language :: Python :: 3.8",
20+
"Programming Language :: Python :: 3.9",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
25+
"Topic :: Scientific/Engineering",
26+
]
27+
dependencies = [
28+
"torch>=1.12.0",
29+
"torchaudio>=0.12.0",
30+
"onnxruntime>=1.18.0",
31+
]
32+
33+
[project.urls]
34+
Homepage = "https://github.com/snakers4/silero-vad"
35+
Issues = "https://github.com/snakers4/silero-vad/issues"

silero-vad.ipynb

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,30 @@
4343
},
4444
"outputs": [],
4545
"source": [
46+
"USE_PIP = True # download model using pip package or torch.hub\n",
4647
"USE_ONNX = False # change this to True if you want to test onnx model\n",
4748
"if USE_ONNX:\n",
4849
" !pip install -q onnxruntime\n",
50+
"if USE_PIP:\n",
51+
" !pip install -q silero-vad\n",
52+
" from silero_vad import (load_silero_vad,\n",
53+
" read_audio,\n",
54+
" get_speech_timestamps,\n",
55+
" save_audio,\n",
56+
" VADIterator,\n",
57+
" collect_chunks)\n",
58+
" model = load_silero_vad(onnx=USE_ONNX)\n",
59+
"else:\n",
60+
" model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad',\n",
61+
" model='silero_vad',\n",
62+
" force_reload=True,\n",
63+
" onnx=USE_ONNX)\n",
4964
"\n",
50-
"model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad',\n",
51-
" model='silero_vad',\n",
52-
" force_reload=True,\n",
53-
" onnx=USE_ONNX)\n",
54-
"\n",
55-
"(get_speech_timestamps,\n",
56-
" save_audio,\n",
57-
" read_audio,\n",
58-
" VADIterator,\n",
59-
" collect_chunks) = utils"
65+
" (get_speech_timestamps,\n",
66+
" save_audio,\n",
67+
" read_audio,\n",
68+
" VADIterator,\n",
69+
" collect_chunks) = utils"
6070
]
6171
},
6272
{

src/silero_vad/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from importlib.metadata import version
2+
try:
3+
__version__ = version(__name__)
4+
except:
5+
pass
6+
7+
from silero_vad.model import load_silero_vad
8+
from silero_vad.utils_vad import (get_speech_timestamps,
9+
save_audio,
10+
read_audio,
11+
VADIterator,
12+
collect_chunks)

src/silero_vad/data/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)