Skip to content

Commit

Permalink
fix/lang_list (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Oct 23, 2023
1 parent ec4e43a commit 24696d9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ovos_stt_plugin_fasterwhisper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
from faster_whisper import WhisperModel, decode_audio
from ovos_bus_client.session import SessionManager
from ovos_config.config import Configuration
from ovos_config.locale import get_default_lang
from ovos_plugin_manager.templates.stt import STT
from ovos_plugin_manager.templates.transformers import AudioTransformer
from ovos_utils.log import LOG
Expand Down Expand Up @@ -29,6 +31,11 @@ def __init__(self, config=None):
device = "cpu"
self.engine = WhisperModel(model, device=device, compute_type=self.compute_type)

@property
def valid_langs(self) -> List[str]:
return list(set([get_default_lang()] +
Configuration().get("secondary_langs", [])))

@staticmethod
def audiochunk2array(audio_data):
# Convert buffer to float32 using NumPy
Expand All @@ -41,10 +48,8 @@ def audiochunk2array(audio_data):
return data

def detect(self, audio, valid_langs=None):
if not valid_langs:
s = SessionManager.get()
valid_langs = s.valid_languages
valid_langs = [l.lower().split("-")[0] for l in valid_langs]
valid_langs = [l.lower().split("-")[0]
for l in valid_langs or self.valid_langs]

if not self.engine.model.is_multilingual:
language = "en"
Expand Down

0 comments on commit 24696d9

Please sign in to comment.