make the dispatcher execte transcription jobs asynchronously

This commit is contained in:
Tomasz Frątczak 2024-02-13 00:08:17 +01:00
parent 7fc073ed19
commit 0a0007e1d0
4 changed files with 21 additions and 2 deletions

View File

@ -1,9 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
from notescriber.transcriber import Transcriber from notescriber.transcriber import Transcriber
from notescriber.dispatcher import Dispatcher
from notescriber.picker import Picker from notescriber.picker import Picker
if __name__ == '__main__': if __name__ == '__main__':
transcriber = Transcriber() transcriber = Transcriber()
picker = Picker("/home/octopusx/Code/test", transcriber) dispatcher = Dispatcher(transcriber)
picker = Picker("/home/octopusx/Code/test", dispatcher)
picker.observe() picker.observe()

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from notescriber import dispatcher
from notescriber import notetaker from notescriber import notetaker
from notescriber import picker from notescriber import picker
from notescriber import transcriber from notescriber import transcriber

16
notescriber/dispatcher.py Normal file
View File

@ -0,0 +1,16 @@
import threading
class Dispatcher:
threads = []
callbackExecutor = None
def __init__(self, callbackExecutor):
self.callbackExecutor = callbackExecutor
def execute(self, audio_file):
thread = threading.Thread(target=self._execute_thread, args=(audio_file.pathname,))
thread.start()
def _execute_thread(self, audio_file):
self.callbackExecutor.execute(audio_file)

View File

@ -3,4 +3,4 @@ class Transcriber:
pass pass
def execute(self, audio_file): def execute(self, audio_file):
print("Transcribing audio file: " + audio_file.pathname) print("Transcribing audio file: " + audio_file)