Skip to content

Commit

Permalink
feat(trController): add state system
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanCarollo committed Mar 18, 2024
1 parent 358610f commit 7cd254c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
30 changes: 27 additions & 3 deletions transcription/TranscriptionController.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
from downloader.DownloaderManager import *
from convertor.ConversionCoordinator import *
from transcriber.TranscriberManager import *
from enum import Enum

class TranscriptionState(Enum):
IDLE = "IDLE"
DOWNLOADINGVIDEO = "DOWNLOADINGVIDEO"
CONVERTINGVIDEO = "CONVERTINGVIDEO"
LOADINGMODEL = "LOADINGMODEL"
TRANSCRIBING = "TRANSCRIBING"


# The idea behind the code is to use https://refactoring.guru/fr/design-patterns/facade
Expand All @@ -22,24 +30,35 @@ def __init__(self):
contextTranscriber = IATranscriberContext("small")
self.trManager = TranscriberManager()
self.trManager.setCurrentAI(ListAI.WHISPER, contextTranscriber)
self.state = TranscriptionState.LOADINGMODEL
pass

# The main function that we need to call, here, the input is only a string
# cause the only way for the user to talk with this object is by passing an
# input text that contains the url // the path of the video
# We may need to thread that in the future
# The callback of this function take a value in parameter so, in this callback, you will need
# to put something like trContext.text = result["text"]
def startTranscription(self, input: str):
transcriberContext = TranscriberContext(input)

self.updateState(TranscriptionState.DOWNLOADINGVIDEO)
downloaderManager = DownloaderManager()
downloaderManager.startDownload(transcriberContext)

self.updateState(TranscriptionState.CONVERTINGVIDEO)
converterCoordinator = ConversionCoordinator.getConversionCoordinator()
conversionResult = converterCoordinator.convert(transcriberContext)

return self.trManager.transcribe(transcriberContext.audioPath)
self.updateState(TranscriptionState.TRANSCRIBING)
result = self.trManager.transcribe(transcriberContext.audioPath)
self.updateState(TranscriptionState.IDLE)
return result

# Update the state of the controller
def updateState(self, state):
DLog.goodlog("updated state into " + str(state))
# In this function, we will set the state and
# TODO : NOTIFY SUBSCRIBERS THAT THE STATE CHANGED CAUSE THIS OBJECT IS AN OBSERVABLE
self.state = state

# For some reason, this function worked as a static even without the @staticmethod... so i searched and lol
# https://stackoverflow.com/questions/52831534/why-is-a-method-of-a-python-class-declared-without-self-and-without-decorators
Expand All @@ -49,3 +68,8 @@ def getInstance() -> 'TranscriptionController' :
if TranscriptionController.instance == None :
TranscriptionController.instance = TranscriptionController()
return TranscriptionController.instance


if __name__ == "__main__":
trCt = TranscriptionController.getInstance();
trCt.startTranscription("https://www.youtube.com/watch?v=z9w6tO4d90U")
1 change: 1 addition & 0 deletions window/scene/mainScene/DragAndDrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def launchTranscription(self, url):
self.transcribe_thread = TranscribeVideoThread(url)
# Connect the callback to the finished signal !
self.transcribe_thread.finished_signal.connect(self.nextPage)
# TODO : ADD A NEW UPDATE STATE SIGNAL AND CONNECT IT TO THE LOADING SCENE
self.transcribe_thread.start()

# To avoid circular import here lol
Expand Down

0 comments on commit 7cd254c

Please sign in to comment.