def order_listener_callback(self, order): """ Receive an order, try to retrieve it in the brain.yml to launch to attached plugins :param order: the sentence received :type order: str """ logger.debug("[Order] Order listener callback called. Order to process: %s" % order) HookManager.on_stop_listening() self.order_to_process = order self.order_listener_callback_called = True # save in kalliope memory the last order Cortex.save('kalliope_last_order', order)
def order_listener_callback(self, order): """ Receive an order, try to retrieve it in the brain.yml to launch to attached plugins :param order: the sentence received :type order: str """ logger.debug( "[MainController] Order listener callback called. Order to process: %s" % order) HookManager.on_stop_listening() self.order_to_process = order self.order_listener_callback_called = True
def order_listener_callback(self, order): """ Receive an order, try to retrieve it in the brain.yml to launch to attached plugins :param order: the sentence received :type order: str """ logger.debug("[Order] Order listener callback called. Order to process: %s" % order) HookManager.on_stop_listening() self.order_to_process = order self.order_listener_callback_called = True # save in kalliope memory the last order Cortex.save('kalliope_last_order', order)
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)