mirror of
https://github.com/snakers4/silero-vad.git
synced 2026-02-05 18:09:22 +08:00
Fx
This commit is contained in:
8
utils.py
8
utils.py
@@ -38,7 +38,7 @@ def read_audio(path: str,
|
|||||||
|
|
||||||
def save_audio(path: str,
|
def save_audio(path: str,
|
||||||
tensor: torch.Tensor,
|
tensor: torch.Tensor,
|
||||||
sr: int):
|
sr: int = 16000):
|
||||||
torchaudio.save(path, tensor, sr)
|
torchaudio.save(path, tensor, sr)
|
||||||
|
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ def get_speech_ts(wav: torch.Tensor,
|
|||||||
|
|
||||||
outs = torch.cat(outs, dim=0)
|
outs = torch.cat(outs, dim=0)
|
||||||
|
|
||||||
buffer = deque(maxlen=num_steps) # when max queue len is reached, first element is dropped
|
buffer = deque(maxlen=num_steps) # maxlen reached => first element dropped
|
||||||
triggered = False
|
triggered = False
|
||||||
speeches = []
|
speeches = []
|
||||||
current_speech = {}
|
current_speech = {}
|
||||||
@@ -113,7 +113,7 @@ class VADiterator:
|
|||||||
self.num_samples = 4000
|
self.num_samples = 4000
|
||||||
self.num_steps = num_steps
|
self.num_steps = num_steps
|
||||||
assert self.num_samples % num_steps == 0
|
assert self.num_samples % num_steps == 0
|
||||||
self.step = int(self.num_samples / num_steps)
|
self.step = int(self.num_samples / num_steps) # 500 samples is good enough
|
||||||
self.prev = torch.zeros(self.num_samples)
|
self.prev = torch.zeros(self.num_samples)
|
||||||
self.last = False
|
self.last = False
|
||||||
self.triggered = False
|
self.triggered = False
|
||||||
@@ -144,7 +144,7 @@ class VADiterator:
|
|||||||
self.prev = wav_chunk
|
self.prev = wav_chunk
|
||||||
|
|
||||||
overlap_chunks = [stacked[i:i+self.num_samples].unsqueeze(0)
|
overlap_chunks = [stacked[i:i+self.num_samples].unsqueeze(0)
|
||||||
for i in range(self.step, self.num_samples+1, self.step)] # 500 sample step is good enough
|
for i in range(self.step, self.num_samples+1, self.step)]
|
||||||
return torch.cat(overlap_chunks, dim=0)
|
return torch.cat(overlap_chunks, dim=0)
|
||||||
|
|
||||||
def state(self, model_out):
|
def state(self, model_out):
|
||||||
|
|||||||
Reference in New Issue
Block a user