Skip to content
Snippets Groups Projects
Commit 055333c4 authored by Eustache Le Bihan's avatar Eustache Le Bihan
Browse files

clean code

parent ec1ee52e
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ from time import perf_counter ...@@ -13,6 +13,7 @@ from time import perf_counter
import numpy as np import numpy as np
import torch import torch
import nltk
from nltk.tokenize import sent_tokenize from nltk.tokenize import sent_tokenize
from rich.console import Console from rich.console import Console
from transformers import ( from transformers import (
...@@ -36,6 +37,11 @@ from utils import ( ...@@ -36,6 +37,11 @@ from utils import (
next_power_of_2 next_power_of_2
) )
# Ensure that the necessary NLTK resources are available
try:
nltk.data.find('tokenizers/punkt_tab')
except LookupError:
nltk.download('punkt_tab')
# caching allows ~50% compilation time reduction # caching allows ~50% compilation time reduction
# see https://docs.google.com/document/d/1y5CRfMLdwEoF1nTk9q8qEu1mgMUuUtvhklPKJ2emLU8/edit#heading=h.o2asbxsrp1ma # see https://docs.google.com/document/d/1y5CRfMLdwEoF1nTk9q8qEu1mgMUuUtvhklPKJ2emLU8/edit#heading=h.o2asbxsrp1ma
...@@ -337,9 +343,9 @@ class VADHandler(BaseHandler): ...@@ -337,9 +343,9 @@ class VADHandler(BaseHandler):
array = torch.cat(vad_output).cpu().numpy() array = torch.cat(vad_output).cpu().numpy()
duration_ms = len(array) / self.sample_rate * 1000 duration_ms = len(array) / self.sample_rate * 1000
if duration_ms < self.min_speech_ms or duration_ms > self.max_speech_ms: if duration_ms < self.min_speech_ms or duration_ms > self.max_speech_ms:
logger.debug(f"audio input of duration: {len(array) / self._sample_rate}s, skipping") logger.debug(f"audio input of duration: {len(array) / self.sample_rate}s, skipping")
else: else:
self._should_listen.clear() self.should_listen.clear()
logger.debug("Stop listening") logger.debug("Stop listening")
yield array yield array
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment