Files
gajim-plugins/stt_voice_messages/models/openai_whisper.py

57 lines
1.7 KiB
Python

# 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 <http://www.gnu.org/licenses/>.
import logging
import typing
from dataclasses import dataclass
from pathlib import Path
from ..helper import Results
from ..model_settings import OpenAIWhisperSettings
from .model 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):
# TODO
self._result: str = ''
self._config = OpenAIWhisperSettings()
@property
def result(self) -> str:
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']
def on_setting(self, key, value):
log.debug('key = %s, value = %s', key, value)
self._config[key] = value