Skip to content

Commit

Permalink
Merge pull request #280 from bclark-videra/test/hubconf-with-ref
Browse files Browse the repository at this point in the history
Use the path to hubconf.py to find models
  • Loading branch information
adamnsandle authored Dec 29, 2022
2 parents a480e85 + df1d520 commit e7c4539
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions hubconf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies = ['torch', 'torchaudio']
import torch
import json
import os
from utils_vad import (init_jit_model,
get_speech_timestamps,
get_number_ts,
Expand Down Expand Up @@ -31,11 +32,11 @@ def silero_vad(onnx=False, force_onnx_cpu=False):
if versiontuple(installed_version) < versiontuple(supported_version):
raise Exception(f'Please install torch {supported_version} or greater ({installed_version} installed)')

hub_dir = torch.hub.get_dir()
model_dir = os.path.join(os.path.dirname(__file__), 'files')
if onnx:
model = OnnxWrapper(f'{hub_dir}/snakers4_silero-vad_master/files/silero_vad.onnx', force_onnx_cpu)
model = OnnxWrapper(os.path.join(model_dir, 'silero_vad.onnx'), force_onnx_cpu)
else:
model = init_jit_model(model_path=f'{hub_dir}/snakers4_silero-vad_master/files/silero_vad.jit')
model = init_jit_model(os.path.join(model_dir, 'silero_vad.jit'))
utils = (get_speech_timestamps,
save_audio,
read_audio,
Expand Down Expand Up @@ -85,18 +86,17 @@ def silero_lang_detector_95(onnx=False, force_onnx_cpu=False):
Returns a model with a set of utils
Please see https://github.com/snakers4/silero-vad for usage examples
"""

hub_dir = torch.hub.get_dir()
if onnx:
url = 'https://models.silero.ai/vad_models/lang_classifier_95.onnx'
else:
url = 'https://models.silero.ai/vad_models/lang_classifier_95.jit'
model = Validator(url, force_onnx_cpu)

with open(f'{hub_dir}/snakers4_silero-vad_master/files/lang_dict_95.json', 'r') as f:
model_dir = os.path.join(os.path.dirname(__file__), 'files')
with open(os.path.join(model_dir, 'lang_dict_95.json'), 'r') as f:
lang_dict = json.load(f)

with open(f'{hub_dir}/snakers4_silero-vad_master/files/lang_group_dict_95.json', 'r') as f:
with open(os.path.join(model_dir, 'lang_group_dict_95.json'), 'r') as f:
lang_group_dict = json.load(f)

utils = (get_language_and_group, read_audio)
Expand Down

0 comments on commit e7c4539

Please sign in to comment.