Exemple #1
0
class TTS(object):
    """
    TTS abstract class to be implemented by all TTS engines.

    It aggregates the minimum required parameters and exposes
    ``execute(sentence)`` function.
    """
    __metaclass__ = ABCMeta

    def __init__(self, lang, voice, validator):
        super(TTS, self).__init__()
        self.lang = lang
        self.voice = voice
        self.filename = '/tmp/tts.wav'
        self.validator = validator
        random.seed()

    def init(self, ws):
        self.ws = ws
        self.enclosure = EnclosureAPI(self.ws)

    @abstractmethod
    def execute(self, sentence):
        pass

    def blink(self, rate=1.0):
        if random.random() < rate:
            self.enclosure.eyes_blink("b")
Exemple #2
0
class TTS(object):
    """
    TTS abstract class to be implemented by all TTS engines.

    It aggregates the minimum required parameters and exposes
    ``execute(sentence)`` function.
    """
    __metaclass__ = ABCMeta

    def __init__(self, lang, voice, validator):
        super(TTS, self).__init__()
        self.lang = lang or 'en-us'
        self.voice = voice
        self.filename = '/tmp/tts.wav'
        self.validator = validator
        random.seed()

    def init(self, ws):
        self.ws = ws
        self.enclosure = EnclosureAPI(self.ws)

    @abstractmethod
    def execute(self, sentence):
        pass

    def blink(self, rate=1.0):
        if random.random() < rate:
            self.enclosure.eyes_blink("b")
Exemple #3
0
class TTS(object):
    """
    TTS abstract class to be implemented by all TTS engines.

    It aggregates the minimum required parameters and exposes
    ``execute(sentence)`` function.
    """
    __metaclass__ = ABCMeta

    def __init__(self, lang, voice, validator):
        super(TTS, self).__init__()
        self.lang = lang or 'en-us'
        self.voice = voice
        self.filename = '/tmp/tts.wav'
        self.validator = validator
        self.enclosure = None
        random.seed()

    def init(self, ws):
        self.ws = ws
        self.enclosure = EnclosureAPI(self.ws)

    @abstractmethod
    def execute(self, sentence):
        ''' This performs TTS, blocking until audio completes

        This performs the TTS sequence.  Upon completion, the sentence will
        have been spoken.   Optionally, the TTS engine may have sent visemes
        to the enclosure by the TTS engine.

        Args:
            sentence (str): Words to be spoken
        '''
        # TODO: Move caching support from mimic_tts to here for all TTS
        pass

    def blink(self, rate=1.0):
        if self.enclosure and random.random() < rate:
            self.enclosure.eyes_blink("b")
class TTS(object):
    """
    TTS abstract class to be implemented by all TTS engines.

    It aggregates the minimum required parameters and exposes
    ``execute(sentence)`` function.
    """
    __metaclass__ = ABCMeta

    def __init__(self, lang, voice, validator):
        super(TTS, self).__init__()
        self.lang = lang or 'en-us'
        self.voice = voice
        self.filename = '/tmp/tts.wav'
        self.validator = validator
        self.enclosure = None
        random.seed()

    def init(self, ws):
        self.ws = ws
        self.enclosure = EnclosureAPI(self.ws)

    @abstractmethod
    def execute(self, sentence):
        ''' This performs TTS, blocking until audio completes

        This performs the TTS sequence.  Upon completion, the sentence will
        have been spoken.   Optionally, the TTS engine may have sent visemes
        to the enclosure by the TTS engine.

        Args:
            sentence (str): Words to be spoken
        '''
        # TODO: Move caching support from mimic_tts to here for all TTS
        pass

    def blink(self, rate=1.0):
        if self.enclosure and random.random() < rate:
            self.enclosure.eyes_blink("b")
Exemple #5
0
    def execute(self, sentence, client):
        enclosure = EnclosureAPI(client)

        random.seed()
        # blink 50% of the time before speaking (only shows up if the
        # mimic TTS generation takes fairly long)
        if (random.random() < 0.5):
            enclosure.eyes_blink("b")

        # invoke mimic, creating WAV and outputting phoneme:duration pairs
        outMimic = subprocess.check_output([
            BIN, '-voice', self.voice, '-t', sentence, '-psdur', "-o",
            "/tmp/mimic.wav"
        ])

        # split into parts
        lisPairs = outMimic.split(" ")

        # covert phonemes to visemes
        visCodes = ''
        for pair in lisPairs:
            pho_dur = pair.split(":")
            if len(pho_dur) != 2:
                continue
            visCodes += self.PhonemeToViseme(pho_dur[0]) + ":"
            visCodes += pho_dur[1] + ","

        # play WAV and walk thru visemes while it plays
        enclosure.mouth_viseme(visCodes)
        subprocess.call(['aplay', '/tmp/mimic.wav'])

        # after speaking, blink 20% of the time
        if (random.random() < 0.2):
            enclosure.eyes_blink("b")

        # delete WAV
        os.remove("/tmp/mimic.wav")