Spaces:
Running
Running
| import abc | |
| import numpy as np | |
| class IASRModel(metaclass=abc.ABCMeta): | |
| """Automatic Speech Recognition Model Interface""" | |
| def __subclasshook__(cls, subclass): | |
| return (hasattr(subclass, 'getTranscript') and | |
| callable(subclass.getTranscript) and | |
| hasattr(subclass, 'getWordLocations') and | |
| callable(subclass.getWordLocations) and | |
| hasattr(subclass, 'processAudio') and | |
| callable(subclass.processAudio)) | |
| def getTranscript(self) -> str: | |
| """Get the transcripts of the process audio""" | |
| raise NotImplementedError | |
| def getWordLocations(self) -> list: | |
| """Get the pair of words location from audio""" | |
| raise NotImplementedError | |
| def processAudio(self, audio): | |
| """Process the audio""" | |
| raise NotImplementedError | |
| class ITranslationModel(metaclass=abc.ABCMeta): | |
| """Translation model""" | |
| def __subclasshook__(cls, subclass): | |
| return (hasattr(subclass, 'translateSentence') and | |
| callable(subclass.translateSentence)) | |
| def translateSentence(self, str) -> str: | |
| """Get the translation of the sentence""" | |
| raise NotImplementedError | |
| class ITextToSpeechModel(metaclass=abc.ABCMeta): | |
| """Text to Speech model""" | |
| def __subclasshook__(cls, subclass): | |
| return (hasattr(subclass, 'getAudioFromSentence') and | |
| callable(subclass.getAudioFromSentence)) | |
| def getAudioFromSentence(self, str) -> np.array: | |
| """Get audio from sentence""" | |
| raise NotImplementedError | |
| class ITextToPhonemModel(metaclass=abc.ABCMeta): | |
| """Text to Phonem model, needed to evaluate the correctness of speech pronunciation""" | |
| def __subclasshook__(cls, subclass): | |
| return (hasattr(subclass, 'convertToPhonem') and | |
| callable(subclass.convertToPhonem)) | |
| def convertToPhonem(self, str) -> str: | |
| """Convert sentence to phonemes""" | |
| raise NotImplementedError | |