def silero_stt(language='en', version='latest', jit_model='jit', **kwargs): """ Silero Speech-To-Text Model(s) language (str): language of the model, now available are ['en', 'de', 'es'] Returns a model, decoder object and a set of utils Please see https://github.com/snakers4/silero-models for usage examples """ from omegaconf import OmegaConf from utils import (init_jit_model, read_audio, read_batch, split_into_batches, prepare_model_input) models_list_file = os.path.join(os.path.dirname(__file__), "models.yml") if not os.path.exists(models_list_file): models_list_file = 'latest_silero_models.yml' if not os.path.exists(models_list_file): torch.hub.download_url_to_file( 'https://raw.githubusercontent.com/snakers4/silero-models/master/models.yml', 'latest_silero_models.yml', progress=False) assert os.path.exists(models_list_file) models = OmegaConf.load(models_list_file) available_languages = list(models.stt_models.keys()) assert language in available_languages model, decoder = init_jit_model( model_url=models.stt_models.get(language).get(version).get(jit_model), **kwargs) utils = (read_batch, split_into_batches, read_audio, prepare_model_input) return model, decoder, utils
def silero_stt(language='en', **kwargs): """ Silero Speech-To-Text Model(s) language (str): language of the model, now available are ['en', 'de', 'es'] Returns a model and a decoder object Please see https://github.com/snakers4/silero-models for usage examples """ models = OmegaConf.load('models.yml') available_languages = list(models.stt_models.keys()) assert language in available_languages return init_jit_model(model_url=models.stt_models.get('en').latest.jit, **kwargs)
def silero_vad(**kwargs): """Silero Voice Activity Detector 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() model = init_jit_model( model_path=f'{hub_dir}/snakers4_silero-vad_master/files/model.jit') utils = (get_speech_ts, save_audio, read_audio, state_generator, single_audio_stream, collect_chunks) return model, utils
def silero_lang_detector(**kwargs): """Silero Language Classifier 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() model = init_jit_model( model_path= f'{hub_dir}/snakers4_silero-vad_master/files/number_detector.jit') utils = (get_language, read_audio) return model, utils
def silero_number_detector(**kwargs): """Silero Number Detector 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() model = init_jit_model( model_path= f'{hub_dir}/snakers4_silero-vad_master/files/number_detector.jit') utils = (get_number_ts, save_audio, read_audio, collect_chunks, drop_chunks) return model, utils
def silero_stt(language='en', **kwargs): """ Silero Speech-To-Text Model(s) language (str): language of the model, now available are ['en', 'de', 'es'] Returns a model, decoder object and a set of utils Please see https://github.com/snakers4/silero-models for usage examples """ torch.hub.download_url_to_file( 'https://raw.githubusercontent.com/snakers4/silero-models/master/models.yml', 'latest_silero_models.yml', progress=False) models = OmegaConf.load('latest_silero_models.yml') available_languages = list(models.stt_models.keys()) assert language in available_languages model, decoder = init_jit_model( model_url=models.stt_models.get(language).latest.jit, **kwargs) utils = (read_batch, split_into_batches, read_audio, prepare_model_input) return model, decoder, utils
START_MSG = '''Привет! Этот бот создан для тестирования Silero TTS: https://github.com/snakers4/silero-models ''' FIRST_STEP = '''Использовать бот просто: 1) Добавьте ударения в свой текст с помощью https://morpher.ru/accentizer/ 2) Отправьте текст и ждите аудиосообщение ''' device = torch.device('cpu') jit_model = dirname(__file__) + '/model/v1_kseniya_16000.jit' model = init_jit_model(jit_model, device=device) bot = telebot.TeleBot(TOKEN, parse_mode=None) @bot.message_handler(commands=['start', 'help']) def send_welcome(message): bot.reply_to(message, START_MSG) bot.reply_to(message, FIRST_STEP) @bot.message_handler(func=lambda message: True) def process_voice_message(message): if not message.text: bot.reply_to(message, 'А где текст??!') return