Ejemplo n.º 1
0
    def run(self):
        stream = self.deepspeech_model.createStream()

        i = 1
        for _bytes, src in self.voiced_audio_generator():
            if _bytes is not None:
                stream.feedAudioContent(np.frombuffer(_bytes, np.int16))
                self.store_audio_data(_bytes, "voiced")
                self.store_audio_data(_bytes, str(i))
            else:
                text = stream.finishStream()
                stream = self.deepspeech_model.createStream()
                if text:
                    logger.debug(f"Transcript #{i}: {text}")
                    publish_message(self, Text(text), src)
                # else:
                #     logger.debug(f"Transcript #{i} is empty!")
                i += 1
Ejemplo n.º 2
0
    def run(self):
        audio = pyaudio.PyAudio()
        stream = audio.open(
            format=pyaudio.paInt16,
            channels=1,
            rate=SpeechToTextListenerTask.sample_rate,
            input=True,
            frames_per_buffer=self.frames_per_buffer,
        )

        while self.running:
            try:
                input_data = stream.read(self.frames_per_buffer)
            except e:
                logger.error(e)
                self.running = False
                break
            finally:
                output_data = self._process_audio_data(input_data)
                publish_message(self, AudioFrame(output_data))

        stream.stop_stream()
        stream.close()
        audio.terminate()
Ejemplo n.º 3
0
 def process_text(self, text: Text):
     if not text.value:
         return
     response = self.chatbot.get_response(text.value)
     if response.text:
         publish_message(self, Text(response.text))
Ejemplo n.º 4
0
 def on_message(self, data):
     logger.debug(f"Received {len(data)} bytes")
     message = Message.from_bytes(data)
     if message is not None:
         publish_message(
             registry.get_task(BoardWebSocketHandlerListenerTask), message)
Ejemplo n.º 5
0
 def speak(self, text: Text) -> None:
     if not text.value:
         logger.warning("Cannot synthesize empty text")
     data = self.synthesize(text.value)
     publish_message(self, AudioFrame(data), text.src)