Voice note transcription
Compare changes
The idea is to leverage dsnote
/"Speech Note" over dbus. We can trigger a transcription whenever the attachment for a voice note is downloaded (behind a default-off setting, of course), and via QML. Audio file goes to dsnote via dbus, and the text comes back.
Why? Because we can.
TODO:
org.mkiol.Speech
dbus endpoint is not available.Documented on the wiki https://gitlab.com/whisperfish/whisperfish/-/wikis/Voice-Note-Transcription
Proof-of-concept in Python, with dsnote
installed, thanks to ChatGPT:
import dbus
import dbus.mainloop.glib
from gi.repository import GLib
def handle_stt_text_decoded(text, lang, task):
print(f'Received signal: text="{text}", lang="{lang}", task={task}')
# Stop the main loop if the signal is received for the specific task ID
if task == task_id:
loop.quit()
def keep_task_alive():
try:
timer = iface.KeepAliveTask(task_id)
print(f'KeepAliveTask called, timer reset to {timer} ms')
return True # Return True to keep the timeout active
except dbus.DBusException as e:
print(f'Failed to keep task alive: {e}')
return False # Return False to stop the timeout
# Initialize the main loop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
# Connect to the session bus
bus = dbus.SessionBus()
# Get the object
obj = bus.get_object('org.mkiol.Speech', '/')
# Get the interface
iface = dbus.Interface(obj, dbus_interface='org.mkiol.Speech')
# Prepare the arguments
file_path = '/home/nemo/.local/share/be.rubdos/harbour-whisperfish/storage/voice_notes/Note_20240626_162731.aac'
lang = 'en'
out_lang = 'en'
options = {'stream_index': 0} # Example QVariantMap, adapt as needed
# Call the method
task_id = iface.SttTranscribeFile(file_path, lang, out_lang, options)
print(f'Task ID: {task_id}')
# Add a signal receiver
bus.add_signal_receiver(handle_stt_text_decoded,
dbus_interface='org.mkiol.Speech',
signal_name='SttTextDecoded')
# Create a GLib main loop to wait for signals
loop = GLib.MainLoop()
GLib.timeout_add_seconds(5, keep_task_alive)
# Run the main loop
print('Waiting for the SttTextDecoded signal...')
loop.run()