diff --git a/CHANGELOG.md b/CHANGELOG.md index 45be9a9..da95e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,12 @@ # Changelog -## [0.6.0a1](https://github.com/OpenVoiceOS/ovos-plugin-manager/tree/0.6.0a1) (2024-11-20) +## [0.7.0a1](https://github.com/OpenVoiceOS/ovos-plugin-manager/tree/0.7.0a1) (2024-11-24) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-plugin-manager/compare/0.5.7a1...0.6.0a1) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-plugin-manager/compare/0.6.0...0.7.0a1) **Merged pull requests:** -- feat: chat history [\#286](https://github.com/OpenVoiceOS/ovos-plugin-manager/pull/286) ([JarbasAl](https://github.com/JarbasAl)) - -## [0.5.7a1](https://github.com/OpenVoiceOS/ovos-plugin-manager/tree/0.5.7a1) (2024-11-18) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-plugin-manager/compare/0.5.6...0.5.7a1) - -**Merged pull requests:** - -- Update `config` default value handling with updated unit test [\#276](https://github.com/OpenVoiceOS/ovos-plugin-manager/pull/276) ([NeonDaniel](https://github.com/NeonDaniel)) +- feat: STT lang detector [\#289](https://github.com/OpenVoiceOS/ovos-plugin-manager/pull/289) ([JarbasAl](https://github.com/JarbasAl)) diff --git a/ovos_plugin_manager/templates/stt.py b/ovos_plugin_manager/templates/stt.py index af7afed..4fef5dc 100644 --- a/ovos_plugin_manager/templates/stt.py +++ b/ovos_plugin_manager/templates/stt.py @@ -8,13 +8,15 @@ from abc import ABCMeta, abstractmethod from queue import Queue from threading import Thread, Event -from typing import List, Tuple, Optional +from typing import List, Tuple, Optional, Set, Union from ovos_config import Configuration from ovos_utils import classproperty -from ovos_utils.log import deprecated -from ovos_utils.process_utils import RuntimeRequirements from ovos_utils.lang import standardize_lang_tag +from ovos_utils.log import deprecated, LOG +from ovos_utils.process_utils import RuntimeRequirements + +from ovos_plugin_manager.templates.transformers import AudioLanguageDetector from ovos_plugin_manager.utils.config import get_plugin_config @@ -31,6 +33,16 @@ def __init__(self, config=None): self.can_stream = False self._recognizer = None + self._detector = None + + def bind(self, detector: AudioLanguageDetector): + self._detector = detector + LOG.debug(f"{self.__class__.__name__} - Assigned lang detector: {detector}") + + def detect_language(self, audio, valid_langs: Optional[Union[Set[str], List[str]]] = None) -> Tuple[str, float]: + if self._detector is None: + raise NotImplementedError(f"{self.__class__.__name__} does not support audio language detection") + return self._detector.detect(audio, valid_langs=valid_langs or self.available_languages) @classproperty def runtime_requirements(self): @@ -79,8 +91,8 @@ def recognizer(self, val): @property def lang(self): return standardize_lang_tag(self._lang or \ - self.config.get("lang") or \ - Configuration().get("lang", "en-US")) + self.config.get("lang") or \ + Configuration().get("lang", "en-US")) @lang.setter def lang(self, val): @@ -124,10 +136,16 @@ def execute(self, audio, language: Optional[str] = None) -> str: def transcribe(self, audio, lang: Optional[str] = None) -> List[Tuple[str, float]]: """transcribe audio data to a list of possible transcriptions and respective confidences""" + if lang is not None and lang == "auto": + try: + lang, prob = self.detect_language(audio, self.available_languages) + except Exception as e: + LOG.error(f"Language detection failed: {e}. Falling back to default language.") + lang = self.lang # Fall back to default language return [(self.execute(audio, lang), 1.0)] @property - def available_languages(self) -> set: + def available_languages(self) -> Set[str]: """Return languages supported by this STT implementation in this state This property should be overridden by the derived class to advertise what languages that engine supports. diff --git a/ovos_plugin_manager/version.py b/ovos_plugin_manager/version.py index 5b44af1..2a9f1bc 100644 --- a/ovos_plugin_manager/version.py +++ b/ovos_plugin_manager/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 0 -VERSION_MINOR = 6 +VERSION_MINOR = 7 VERSION_BUILD = 0 -VERSION_ALPHA = 0 +VERSION_ALPHA = 1 # END_VERSION_BLOCK