Exemplo n.º 1
0
    def execute(self, sentence, ident=None):
        """
            Convert sentence to speech, preprocessing out unsupported ssml

            The method caches results if possible using the hash of the
            sentence.

            Args:
                sentence:   Sentence to be spoken
                ident:      Id reference to current interaction
        """
        sentence = self.validate_ssml(sentence)

        create_signal("isSpeaking")
        if self.phonetic_spelling:
            for word in re.findall(r"[\w']+", sentence):
                if word.lower() in self.spellings:
                    sentence = sentence.replace(word,
                                                self.spellings[word.lower()])

        key = str(hashlib.md5(sentence.encode('utf-8', 'ignore')).hexdigest())
        wav_file = os.path.join(owo.util.get_cache_directory("tts"),
                                key + '.' + self.audio_ext)

        if os.path.exists(wav_file):
            LOG.debug("TTS cache hit")
            phonemes = self.load_phonemes(key)
        else:
            wav_file, phonemes = self.get_tts(sentence, wav_file)
            if phonemes:
                self.save_phonemes(key, phonemes)

        vis = self.visime(phonemes)
        self.queue.put((self.audio_ext, wav_file, vis, ident))
Exemplo n.º 2
0
 def test_wait_while_speaking(self):
     # Check that test terminates
     create_signal('isSpeaking')
     Thread(target=wait_while_speaking_thread).start()
     sleep(2)
     self.assertFalse(done_waiting)
     check_for_signal('isSpeaking')
     sleep(2)
     self.assertTrue(done_waiting)
Exemplo n.º 3
0
    def test_check_signal(self):
        if exists('/tmp/OwO'):
            rmtree('/tmp/OwO')
        # check that signal is not found if file does not exist
        self.assertFalse(check_for_signal('test_signal'))

        # Check that the signal is found when created
        create_signal('test_signal')
        self.assertTrue(check_for_signal('test_signal'))
        # Check that the signal is removed after use
        self.assertFalse(isfile('/tmp/OwO/ipc/signal/test_signal'))
Exemplo n.º 4
0
    def execute(self, sentence, ident=None):
        """request and play mimic2 wav audio

        Args:
            sentence (str): sentence to synthesize from mimic2
            ident (optional): Defaults to None.
        """
        create_signal("isSpeaking")

        sentence = self._normalized_numbers(sentence)
        chunks = sentence_chunker(sentence, self.chunk_size)
        for idx, req in enumerate(self._requests(chunks)):
            results = req.result().json()
            audio = base64.b64decode(results['audio_base64'])
            vis = self.visime(results['visimes'])
            key = str(
                hashlib.md5(chunks[idx].encode('utf-8', 'ignore')).hexdigest())
            wav_file = os.path.join(get_cache_directory("tts"),
                                    key + '.' + self.audio_ext)
            with open(wav_file, 'wb') as f:
                f.write(audio)
            self.queue.put((self.audio_ext, wav_file, vis, ident))
Exemplo n.º 5
0
def _start_listener(message):
    """
        Force OwO to start listening (as if 'Hey OwO' was spoken)
    """
    create_signal('startListening')
Exemplo n.º 6
0
 def test_is_speaking(self):
     create_signal('isSpeaking')
     self.assertTrue(owo.audio.is_speaking())
     # Check that the signal hasn't been removed
     self.assertTrue(check_for_signal('isSpeaking'))
     self.assertFalse(owo.audio.is_speaking())
Exemplo n.º 7
0
 def test_create_signal(self):
     create_signal('test_signal')
     self.assertTrue(isfile('/tmp/OwO/ipc/signal/test_signal'))
Exemplo n.º 8
0
    def process(self, data):
        # TODO: Look into removing this emit altogether.
        # We need to check if any other serial bus messages
        # are handled by other parts of the code
        if "owo.stop" not in data:
            self.bus.emit(Message(data))

        if "Command: system.version" in data:
            # This happens in response to the "system.version" message
            # sent during the construction of Enclosure()
            self.bus.emit(Message("enclosure.started"))

        if "owo.stop" in data:
            if has_been_paired():
                create_signal('buttonPress')
                self.bus.emit(Message("owo.stop"))

        if "volume.up" in data:
            self.bus.emit(Message("owo.volume.increase",
                                  {'play_sound': True}))

        if "volume.down" in data:
            self.bus.emit(Message("owo.volume.decrease",
                                  {'play_sound': True}))

        if "system.test.begin" in data:
            self.bus.emit(Message('recognizer_loop:sleep'))

        if "system.test.end" in data:
            self.bus.emit(Message('recognizer_loop:wake_up'))

        if "mic.test" in data:
            mixer = Mixer()
            prev_vol = mixer.getvolume()[0]
            mixer.setvolume(35)
            self.bus.emit(Message("speak", {
                'utterance': "I am testing one two three"}))

            time.sleep(0.5)  # Prevents recording the loud button press
            record("/tmp/test.wav", 3.0)
            mixer.setvolume(prev_vol)
            play_wav("/tmp/test.wav").communicate()

            # Test audio muting on arduino
            subprocess.call('speaker-test -P 10 -l 0 -s 1', shell=True)

        if "unit.shutdown" in data:
            # Eyes to soft gray on shutdown
            self.bus.emit(Message("enclosure.eyes.color",
                                  {'r': 70, 'g': 65, 'b': 69}))
            self.bus.emit(
                Message("enclosure.eyes.timedspin",
                        {'length': 12000}))
            self.bus.emit(Message("enclosure.mouth.reset"))
            time.sleep(0.5)  # give the system time to pass the message
            self.bus.emit(Message("system.shutdown"))

        if "unit.reboot" in data:
            # Eyes to soft gray on reboot
            self.bus.emit(Message("enclosure.eyes.color",
                                  {'r': 70, 'g': 65, 'b': 69}))
            self.bus.emit(Message("enclosure.eyes.spin"))
            self.bus.emit(Message("enclosure.mouth.reset"))
            time.sleep(0.5)  # give the system time to pass the message
            self.bus.emit(Message("system.reboot"))

        if "unit.setwifi" in data:
            self.bus.emit(Message("system.wifi.setup", {'lang': self.lang}))

        if "unit.factory-reset" in data:
            self.bus.emit(Message("speak", {
                'utterance': owo.dialog.get("reset to factory defaults")}))
            subprocess.call(
                'rm ~/.OwO/identity/identity2.json',
                shell=True)
            self.bus.emit(Message("system.wifi.reset"))
            self.bus.emit(Message("system.ssh.disable"))
            wait_while_speaking()
            self.bus.emit(Message("enclosure.mouth.reset"))
            self.bus.emit(Message("enclosure.eyes.spin"))
            self.bus.emit(Message("enclosure.mouth.reset"))
            time.sleep(5)  # give the system time to process all messages
            self.bus.emit(Message("system.reboot"))

        if "unit.enable-ssh" in data:
            # This is handled by the wifi client
            self.bus.emit(Message("system.ssh.enable"))
            self.bus.emit(Message("speak", {
                'utterance': owo.dialog.get("ssh enabled")}))

        if "unit.disable-ssh" in data:
            # This is handled by the wifi client
            self.bus.emit(Message("system.ssh.disable"))
            self.bus.emit(Message("speak", {
                'utterance': owo.dialog.get("ssh disabled")}))

        if "unit.enable-learning" in data or "unit.disable-learning" in data:
            enable = 'enable' in data
            word = 'enabled' if enable else 'disabled'

            LOG.info("Setting opt_in to: " + word)
            new_config = {'opt_in': enable}
            user_config = LocalConf(USER_CONFIG)
            user_config.merge(new_config)
            user_config.store()

            self.bus.emit(Message("speak", {
                'utterance': owo.dialog.get("learning " + word)}))