75 lines
2.6 KiB
Python
75 lines
2.6 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/>.
|
|
|
|
from __future__ import annotations
|
|
|
|
from functools import partial
|
|
|
|
from gajim.plugins import GajimPlugin
|
|
from gajim.plugins.plugins_i18n import _
|
|
|
|
from .gtk.config_dialog import *
|
|
from .gtk.sttbox import STTBox
|
|
from .models.model_settings import *
|
|
|
|
log = logging.getLogger('gajim.p.stt_voice_messages')
|
|
|
|
|
|
class STTVoiceMessagesPlugin(GajimPlugin):
|
|
def init(self) -> None:
|
|
self.description = _('Transcribes voice messages to text.')
|
|
|
|
self.config_default_values = {
|
|
'auto_transcribe': (False, ''),
|
|
'model': ('model_openaiwhisper', ''),
|
|
'model_openaiwhisper': (
|
|
OpenAIWhisperSettings(
|
|
model_size='tiny',
|
|
translate_to_english=False),
|
|
''),
|
|
'model_faster-whisper': (
|
|
FasterWhisperSettings(
|
|
model_size='tiny',
|
|
translate_to_english=False),
|
|
'')
|
|
}
|
|
|
|
self._config = Configuration(self)
|
|
self._config.check_available_moduls()
|
|
self.config_dialog = partial(STTVoiceMessagesConfigDialog, self._config)
|
|
|
|
self.gui_extension_points = {
|
|
'preview_audio': (self._on_preview_audio_created, None),
|
|
}
|
|
|
|
self._audio_file: str = ''
|
|
self._preview_audio_widget = None
|
|
self._stt_box = None
|
|
|
|
def _on_preview_audio_created(self,
|
|
preview_audio_widget: Gtk.Box,
|
|
audio_file: Path
|
|
) -> None:
|
|
self._preview_audio_widget = preview_audio_widget
|
|
self._audio_file = audio_file.as_posix()
|
|
self._create_stt_box()
|
|
|
|
def _create_stt_box(self) -> None:
|
|
assert self._preview_audio_widget is not None
|
|
self._stt_box = STTBox(self._preview_audio_widget,
|
|
self.config,
|
|
self._audio_file)
|
|
self._preview_audio_widget.pack_end(self._stt_box, False, False, 0)
|