Files
gajim-plugins/stt_voice_messages/stt_voice_messages.py
T
2026-08-07 04:23:44 -03:00

71 lines
2.2 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
import logging
from functools import partial
from pathlib import Path
from gi.repository import Gtk
from gajim.plugins import GajimPlugin
from gajim.plugins.plugins_i18n import _
from .gtk.config_dialog import STTVoiceMessagesConfigDialog
from .gtk.sttbox import STTBox
from .model import OnnxAsrModel
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_id": ("nemo-parakeet-tdt-0.6b-v3", ""),
"quantization": ("int8", ""),
}
self._model = OnnxAsrModel(
str(self.config["model_id"]), str(self.config["quantization"])
)
self.config_dialog = partial(STTVoiceMessagesConfigDialog, self)
self.gui_extension_points = {
"preview_audio": (self._on_preview_audio, None),
}
@property
def model(self) -> OnnxAsrModel:
return self._model
def deactivate(self) -> None:
self._model.unload_now()
def _on_preview_audio(
self, drawing_box: Gtk.Box, control_box: Gtk.Box, audio_file: Path
) -> None:
content_box = drawing_box.get_parent().get_parent()
stt_box = STTBox(self._model, audio_file)
control_box.append(stt_box.button)
content_box.append(stt_box)
if self.config["auto_transcribe"]:
stt_box.transcribe()