def start_order_listener_thread(self): """ Start the STT engine thread """ logger.debug("[Order] Entering state: %s" % self.state) HookManager.on_start_listening() # start listening for an order self.order_listener_callback_called = False self.order_listener = OrderListener(callback=self.order_listener_callback) self.order_listener.daemon = True self.order_listener.start() self.next_state()
def start_order_listener_thread(self): """ Start the STT engine thread """ logger.debug("[Order] Entering state: %s" % self.state) HookManager.on_start_listening() # start listening for an order self.order_listener_callback_called = False self.order_listener = OrderListener(callback=self.order_listener_callback) self.order_listener.daemon = True self.order_listener.start() self.next_state()
def get_audio_from_stt(callback): """ Call the default STT to get an audio sample and return it into the callback method :param callback: A callback function """ HookManager.on_start_listening() # call the order listener ol = OrderListener(callback=callback) ol.start() ol.join() # wait that the STT engine has finish his job (or the neurotransmitter neuron will be killed) if ol.stt_instance is not None: ol.stt_instance.join() HookManager.on_stop_listening()
def start_recording(self): # pyaudio can work but alsa-lib spiting out error messages, to avoid this I used a method to suppress the messages found on stackoverflow # https://stackoverflow.com/questions/7088672/pyaudio-working-but-spits-out-error-messages-each-time with self.noalsaerr(): audio = pyaudio.PyAudio() FORMAT = pyaudio.paInt32 if self.format == "paInt16": FORMAT = pyaudio.paInt16 if self.format == "paInt24": FORMAT = pyaudio.paInt24 stream = audio.open(format=FORMAT, channels=self.channels, rate=self.rate, input=True, frames_per_buffer=self.chunk) Utils.print_info("[ Recorder ] Is recording...") HookManager.on_start_listening() frames = [] for i in range(0, int(self.rate / self.chunk * self.seconds)): data = stream.read(self.chunk) frames.append(data) stream.stop_stream() stream.close() audio.terminate() HookManager.on_stop_listening() waveFile = wave.open(self.output, 'wb') waveFile.setnchannels(2) waveFile.setsampwidth(audio.get_sample_size(FORMAT)) waveFile.setframerate(self.rate) waveFile.writeframes(b''.join(frames)) waveFile.close() Utils.print_info("[ Recorder ] Record saved to %s" % self.output) if self.playback: self.playback_file(self.output)