forked from altalt-org/Lightning-SimulWhisper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply_vad_iterator.py
More file actions
46 lines (32 loc) · 1.23 KB
/
apply_vad_iterator.py
File metadata and controls
46 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# for debugging only
from whisper_streaming.whisper_online_main import load_audio_chunk, load_audio
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('--vac-chunk-size', type=float, default=0.04,
help='VAC sample size in seconds.')
parser.add_argument('audio_path', type=str, help="Filename of 16kHz mono channel wav, on which live streaming is simulated.")
parser.add_argument('--start_at', type=float, default=0.0, help='Start processing audio at this time.')
args = parser.parse_args()
SAMPLING_RATE = 16000
duration = len(load_audio(args.audio_path))/SAMPLING_RATE
from whisper_streaming.silero_vad_iterator import FixedVADIterator
import torch
model, _ = torch.hub.load(
repo_or_dir='snakers4/silero-vad',
model='silero_vad'
)
vac = FixedVADIterator(model)
b, e = args.start_at, args.start_at+args.vac_chunk_size
ret_beg = None
while e <= duration:
audio = load_audio_chunk(args.audio_path, b, e)
x = vac(audio,return_seconds=True)
if x is not None:
print(b,e,x,file=sys.stderr)
if 'start' in x:
ret_beg = x['start']
if 'end' in x:
print(ret_beg, x['end'], "segment",sep="\t")
b = e
e += args.vac_chunk_size