def create(module=None): module = module or "amazon" config = get_neon_lang_config() module = module or config.get("translation_module", "google") # TODO: Check file locations DM if module == "amazon" \ and get_neon_tts_config()["amazon"].get("aws_access_key_id", "") == "": from neon_utils.authentication_utils import find_neon_aws_keys, populate_amazon_keys_config try: config_keys = find_neon_aws_keys() populate_amazon_keys_config(config_keys) except FileNotFoundError: LOG.debug("Amazon credentials not available") module = "google" except Exception as e: LOG.error(e) module = "google" try: clazz = TranslatorFactory.CLASSES.get(module) return clazz() except Exception as e: # The translate backend failed to start. Report it and fall back to # default. LOG.exception( 'The selected translator backend could not be loaded, ' 'falling back to default...') LOG.error(e) if module != 'google': return GoogleTranslator() else: raise
def transcribe(self, audio, lang): def send_unknown_intent(): """ Send message that nothing was transcribed. """ self.loop.emit('recognizer_loop:speech.recognition.unknown') try: # Invoke the STT engine on the audio clip try: transcriptions = self.loop.stt.execute(audio, language=lang) except Exception as e: if self.loop.fallback_stt: LOG.warning(f"Using fallback STT, main plugin failed: {e}") transcriptions = self.loop.fallback_stt.execute( audio, language=lang) else: raise e if isinstance(transcriptions, str): LOG.info("Casting str transcriptions to list") transcriptions = [transcriptions] if transcriptions is not None: transcriptions = [t.lower().strip() for t in transcriptions] LOG.debug(f"STT: {transcriptions}") else: send_unknown_intent() LOG.info('no words were transcribed') return transcriptions except Exception as e: send_unknown_intent() LOG.error(e) LOG.exception("Speech Recognition could not understand audio") return None
def create(module=None): module = module or "fastlang" config = get_neon_lang_config() module = module or config.get("detection_module", "fastlang") try: clazz = DetectorFactory.CLASSES.get(module) return clazz() except Exception as e: # The translate backend failed to start. Report it and fall back to # default. LOG.exception( 'The selected language detector backend could not be loaded, ' 'falling back to default...') LOG.error(e) if module != 'fastlang': return FastLangDetector() else: raise