def log(message, log_level="warning"): set_debug = config.ConfigDeepSpeech().get_config("debug") if set_debug == "1": logging.getLogger(None).setLevel(logging.DEBUG) if log_level == "debug": logging.debug(message) elif log_level == "info": logging.info(message) elif log_level == "error": logging.error(message) else: logging.warning(message)
class SpeechServerMain(AppConfig): name = 'speech_server_main' conf = config.ConfigDeepSpeech() model = conf.get_config('model') lm = conf.get_config('lm') trie = conf.get_config('trie') ds = Model(model, BEAM_WIDTH) if lm and trie: ds.enableDecoderWithLM(lm, trie, LM_ALPHA, LM_BETA) def ready(self): print("Deepspeech Server Initialization")
class SpeechServerMain(AppConfig): name = 'speech_server_main' conf = config.ConfigDeepSpeech() model = conf.get_config('model') alphabet = conf.get_config('alphabet') lm = conf.get_config('lm') trie = conf.get_config('trie') ds = Model(model, N_FEATURES, N_CONTEXT, alphabet, BEAM_WIDTH) if lm and trie: ds.enableDecoderWithLM(alphabet, lm, trie, LM_WEIGHT, VALID_WORD_COUNT_WEIGHT) def ready(self): print("Deepspeech Server Initialization")
''' Channel consumers ''' from datetime import datetime from speech_server_main.config import config from .deepspeech import deepspeech as ds import os, re conf = config.ConfigDeepSpeech() audiofiledir = conf.get_config('audiofiledir') def ws_connect(message): # Accept the incoming connection message.reply_channel.send({"accept": True}) print('websocket connected') def ws_message(message): print('ws message received') file_name = audiofiledir + 'ws_generated' + datetime.now().strftime( '%y-%m-%d_%H%M%S') with open(file_name, 'wb') as fp: fp.write(message.content['bytes']) fp.flush() msg = ds.stt(file_name) message.reply_channel.send({'text': msg})
import scipy.io.wavfile as wav from speech_server_main.apps import SpeechServerMain from speech_server_main.config import config from speech_server_main import logging audiolength = float(config.ConfigDeepSpeech().get_config("audiofilelength")) def stt(audioPath, from_websocket=False): try: logging.log("Inside deepspeech.stt function", "info") text = "" fs, audio = wav.read(audioPath) if fs == 16000: if from_websocket or check_audio_lenth(len(audio)): logging.log("Starting transcribing...", "info") text = SpeechServerMain.ds.stt(audio, fs) logging.log("Audio transcribed.", "info") elif not from_websocket: text = "Audio should be less than " + str(audiolength) + " seconds." else: text = "Frame rate of submitted audio should be 16000 kHz." #print('after inference: %s' % text) except Exception as err: logging.log("exception occurred: {0}".format(err), "error") text = "Some error occurred while transcribing." return text def check_audio_lenth(len_audio): len_audio = len_audio / 16000 if len_audio > audiolength: