def _find_synapse_to_run(cls, brain, settings, order): """ Find the list of the synapse matching the order. Note: we use named tuples: tuple_synapse_order = collections.namedtuple('tuple_synapse_matchingOrder',['synapse', 'order']) :param brain: the brain :param settings: the settings :param order: the provided order to match :return: the list of synapses launched (named tuples) """ synapse_to_run = cls._get_matching_synapse_list(brain.synapses, order) if not synapse_to_run: Utils.print_info("No synapse match the captured order: %s" % order) if settings.default_synapse is not None: default_synapse = cls._get_default_synapse_from_sysnapses_list( brain.synapses, settings.default_synapse) if default_synapse is not None: logger.debug("Default synapse found %s" % default_synapse) Utils.print_info("Default synapse found: %s, running it" % default_synapse.name) tuple_synapse_order = collections.namedtuple( 'tuple_synapse_matchingOrder', ['synapse', 'order']) synapse_to_run.append( tuple_synapse_order(synapse=default_synapse, order="")) return synapse_to_run
def signal_handler(signal, frame): """ Used to catch a keyboard signal like Ctrl+C in order to kill the kalliope program :param signal: signal handler :param frame: execution frame """ print "\n" Utils.print_info("Ctrl+C pressed. Killing Kalliope") sys.exit(0)
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)
def playback_file(self, output): if os.path.isfile(output): Utils.print_info("[ Recorder ] Playback %s" % output) return self.player.play(output) else: if self.file_name == "default.wav": Utils.print_info("[ Recorder ] Nothing to play") else: Utils.print_info("[ Recorder ] %s not found" % output)