Spaces:
Running
Running
File size: 2,003 Bytes
28d0c5f 74a35d9 28d0c5f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import abc
import numpy as np
class IASRModel(metaclass=abc.ABCMeta):
@classmethod
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))
@abc.abstractmethod
def getTranscript(self) -> str:
"""Get the transcripts of the process audio"""
raise NotImplementedError
@abc.abstractmethod
def getWordLocations(self) -> list:
"""Get the pair of words location from audio"""
raise NotImplementedError
@abc.abstractmethod
def processAudio(self, audio):
"""Process the audio"""
raise NotImplementedError
class ITranslationModel(metaclass=abc.ABCMeta):
@classmethod
def __subclasshook__(cls, subclass):
return (hasattr(subclass, 'translateSentence') and
callable(subclass.translateSentence))
@abc.abstractmethod
def translateSentence(self, str) -> str:
"""Get the translation of the sentence"""
raise NotImplementedError
class ITextToSpeechModel(metaclass=abc.ABCMeta):
@classmethod
def __subclasshook__(cls, subclass):
return (hasattr(subclass, 'getAudioFromSentence') and
callable(subclass.getAudioFromSentence))
@abc.abstractmethod
def getAudioFromSentence(self, str) -> np.array:
"""Get audio from sentence"""
raise NotImplementedError
class ITextToPhonemModel(metaclass=abc.ABCMeta):
@classmethod
def __subclasshook__(cls, subclass):
return (hasattr(subclass, 'convertToPhonem') and
callable(subclass.convertToPhonem))
@abc.abstractmethod
def convertToPhonem(self, str) -> str:
"""Convert sentence to phonemes"""
raise NotImplementedError
|