Improve multi modul support and refactor
This commit is contained in:
@@ -19,5 +19,5 @@ from dataclasses import dataclass, field
|
||||
|
||||
@dataclass
|
||||
class OpenAIWhisperSettings:
|
||||
whisperai_model_size: str = field(default='tiny', init=True)
|
||||
|
||||
model_size: str = field(default='tiny', init=True)
|
||||
translate_to_english: bool = field(default=False, init=True)
|
||||
@@ -16,8 +16,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
|
||||
from gajim.gtk.const import Setting
|
||||
|
||||
from ..helper import Results
|
||||
|
||||
|
||||
@@ -26,7 +24,3 @@ class Model(ABC):
|
||||
@abstractmethod
|
||||
def transcribe(self, result: Results, audio_file: Path) -> str:
|
||||
return ''
|
||||
|
||||
@abstractmethod
|
||||
def on_setting(self, setting: Setting):
|
||||
pass
|
||||
@@ -46,11 +46,10 @@ class WhisperModel(Model):
|
||||
return self._result
|
||||
|
||||
def transcribe(self, result: Results, audio_file: Path) -> str:
|
||||
model = whisper.load_model(self._config['whisperai_model_size'])
|
||||
log.debug('model size is used = %s', self._config['whisperai_model_size'])
|
||||
result.text = model.transcribe(audio_file)['text']
|
||||
model = whisper.load_model(self._config.model_size)
|
||||
log.debug('model size is used = %s', self._config.model_size)
|
||||
result.text = model.transcribe(audio_file)['text'] # pyright: ignore [reportAttributeAccessIssue]
|
||||
|
||||
def on_setting(self, key, value):
|
||||
log.debug('key = %s, value = %s', key, value)
|
||||
self._config[key] = value
|
||||
def set_config(self, config: OpenAIWhisperSettings) -> None:
|
||||
self._config = config
|
||||
|
||||
|
||||
Reference in New Issue
Block a user