diff --git a/notescriber.py b/notescriber.py index 3e1b92a..dfe474c 100755 --- a/notescriber.py +++ b/notescriber.py @@ -1,11 +1,12 @@ #!/usr/bin/env python -from notescriber.transcriber import Transcriber -from notescriber.dispatcher import Dispatcher -from notescriber.picker import Picker +# from notescriber.transcriber import Transcriber +# from notescriber.dispatcher import Dispatcher +# from notescriber.picker import Picker +from notescriber import picker, dispatcher if __name__ == '__main__': - transcriber = Transcriber() - dispatcher = Dispatcher(transcriber) - picker = Picker("/home/octopusx/Code/test", dispatcher) - picker.observe() \ No newline at end of file + + picker.observe() + # dispatcher.halt() + # picker.halt() \ No newline at end of file diff --git a/notescriber/__init__.py b/notescriber/__init__.py index 7ff0332..299b192 100644 --- a/notescriber/__init__.py +++ b/notescriber/__init__.py @@ -3,3 +3,11 @@ from notescriber import dispatcher from notescriber import notetaker from notescriber import picker from notescriber import transcriber + +dispatcher = dispatcher.Dispatcher() +notetaker = notetaker.Notetaker() +picker = picker.Picker("/home/octopusx/Code/test",dispatcher) +transcriber = transcriber.Transcriber() + +dispatcher.add_note_generator(notetaker) +dispatcher.add_audio_processor(transcriber) \ No newline at end of file diff --git a/notescriber/dispatcher.py b/notescriber/dispatcher.py index b7d2eb6..2c80a3d 100644 --- a/notescriber/dispatcher.py +++ b/notescriber/dispatcher.py @@ -1,26 +1,33 @@ import threading -import os class Dispatcher: threads = [] - callbackExecutor = None + audioProcessor = None extensionFilter = None + noteGenerator = None - def __init__(self, callbackExecutor): - self.callbackExecutor = callbackExecutor + def __init__(self): + pass - def apply_filter(self, audio_file): - # TODO: return True if audio file is valid, based on name, extension, and other criteria - if os.path.isdir(audio_file): - return False - return True + def add_audio_processor(self, audioProcessor): + self.audioProcessor = audioProcessor - def execute(self, audio_file): - if self.apply_filter(audio_file.pathname): - self.threads.append(threading.Thread(target=self._execute_thread, args=(audio_file.pathname,))) - self.threads[-1].start() - # TODO: we need to have a way to wipe old threads, otherwise we will have a memory leak + def add_note_generator(self, noteGenerator): + self.noteGenerator = noteGenerator + + def process_audio_file(self, audio_file): + self.threads.append(threading.Thread(target=self._execute_thread, args=(audio_file.pathname,))) + self.threads[-1].start() + # TODO: we need to have a way to wipe old threads, otherwise we will have a memory leak + + def generate_note(self, note): + pass def _execute_thread(self, audio_file): - self.callbackExecutor.execute(audio_file) \ No newline at end of file + note = self.audioProcessor.execute(audio_file) + self.noteGenerator.generate_note(note) + + def halt(self): + for thread in self.threads: + thread.join(10) \ No newline at end of file diff --git a/notescriber/notetaker.py b/notescriber/notetaker.py index e69de29..bbd8930 100644 --- a/notescriber/notetaker.py +++ b/notescriber/notetaker.py @@ -0,0 +1,7 @@ +class Notetaker: + + def __init__(self): + pass + + def generate_note(self, note): + print("Received note: " + note) \ No newline at end of file diff --git a/notescriber/picker.py b/notescriber/picker.py index 834b091..06efab9 100644 --- a/notescriber/picker.py +++ b/notescriber/picker.py @@ -1,23 +1,34 @@ import pyinotify +import os class EventHandler(pyinotify.ProcessEvent): def process_IN_CREATE(self, event): print(f'New file: {event.pathname}') return event.pathname + + def apply_filter(self, audio_file): + # TODO: return True if audio file is valid, based on name, extension, and other criteria + if os.path.isdir(audio_file): + return False + return True class Picker: directory = None - callbackObject = None + dispatcher = None + notifier = None - def __init__(self, directory, callbackObject): + def __init__(self, directory, dispatcher): self.directory = directory - self.callbackObject = callbackObject + self.dispatcher = dispatcher def observe(self): wm = pyinotify.WatchManager() - notifier = pyinotify.Notifier(wm, EventHandler()) - wm.add_watch(self.directory, pyinotify.IN_CREATE, self.callbackObject.execute) + self.notifier = pyinotify.Notifier(wm, EventHandler()) + wm.add_watch(self.directory, pyinotify.IN_CREATE, self.dispatcher.process_audio_file) print(f'Watching {self.directory} for changes...') - notifier.loop() + self.notifier.loop() + + def halt(self): + self.notifier.stop() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4ba2ae9..f7a8e7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -whisper==1.1.10 +openai-whisper==20231117 pyinotify==0.9.6 \ No newline at end of file diff --git a/tests/fixtures/hello.wav b/tests/fixtures/hello.wav new file mode 100644 index 0000000..412f283 Binary files /dev/null and b/tests/fixtures/hello.wav differ