# This file is part of Gajim. # # Gajim is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Gajim is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Gajim. If not, see . import logging import typing from dataclasses import dataclass from pathlib import Path from ..helper import Results from .model_settings import OpenAIWhisperSettings from .model_template import Model log = logging.getLogger('gajim.p.sttvm_whisper') try: import whisper OPENAI_WHISPER_AVAILABLE = True except ModuleNotFoundError: if typing.TYPE_CHECKING: import whisper @dataclass class Configuration: model_size: str class WhisperModel(Model): def __init__(self): self._result: str = '' self._config = OpenAIWhisperSettings() @property def result(self) -> str: return self._result def transcribe(self, result: Results, audio_file: Path) -> None: 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 set_config(self, config: OpenAIWhisperSettings) -> None: self._config = config