Exemplo n.º 1
0
 def stop(self) -> None:
     if not self.is_on:
         logger.debug("Audio handler is already off. Ignoring.")
     logger.debug("Stopping audio handler.")
     self.__wrap('stop')
     self.is_on = False
     logger.info("Stopped audio handler.")
Exemplo n.º 2
0
	def init(self) -> None:
		# config['sauron.hardware.arduino.reset_time']
		# config.sensors['sampling_interval_milliseconds']
		self._connect()
		self.flash_status(StatusCode.INIT)
		self._init_pins()
		self.set_illumination(1)
		logger.info('Finished initializing board')
Exemplo n.º 3
0
 def start(self) -> None:
     if self.is_on:
         logger.debug("Audio handler is already on. Ignoring.")
         return
     self.__wrap('start')
     logger.debug("Starting audio handler.")
     self.is_on = True
     logger.info("Started audio handler.")
Exemplo n.º 4
0
	def exit(self) -> None:
		logger.info("Setting pins to off and shutting down Arduino")
		try:
			self.stop_all_stimuli()
			self.set_illumination(0)
			self.reset_all_sensors()
			self.flash_status(StatusCode.SHUTDOWN)
		finally:
			try:
				asyncio.ensure_future(self._kill())
			finally:
				self._board.core.serial_port.my_serial.close()
		logger.debug("Finished shutting down Arudino")
Exemplo n.º 5
0
 def _arm(self, **kwargs) -> None:
     logger.info("Recording {} to {}".format(self.name(), self.output_path))
     make_dirs(dirname(self.log_file))
     self.timestamps = []
     self.frames = []
     try:
         self._p = pyaudio.PyAudio()
         self._stream = self._p.open(
             format=self.audio_format,
             channels=self.channels,
             rate=self.sample_rate,
             input=True,
             frames_per_buffer=self.frames_per_buffer)
     except Exception as e:
         logger.fatal("Failed to start microphone.")
         #warn_user("Failed to start microphone.")
         raise e
Exemplo n.º 6
0
 def save(self):
     try:
         logger.info("Writing microphone data...")
         logger.debug("Writing microphone timestamps")
         with open(self.timestamp_file_path, 'w') as f:
             for ts in self.timestamps:
                 f.write(stamp(ts) + '\n')
         logger.debug("Writing microphone WAV data")
         wf = wave.open(self.log_file, 'wb')
         try:
             wf.setnchannels(self.channels)
             wf.setsampwidth(self._p.get_sample_size(self.audio_format))
             wf.setframerate(self.sample_rate)
             wf.writeframes(b''.join(self.frames))
         finally:
             wf.close()
     except Exception as e:
         #warn_user("Microphone failed while writing the .wav file")
         raise e
     logger.info("Finished writing microphone data.")
Exemplo n.º 7
0
 def _kill(self):
     logger.info("Terminating microphone...")
     logger.debug("Ending microphone process")
     try:
         self._p.terminate()  # failing here is probably bad
     except Exception as b:
         logger.warning("Failed to terminate microphone process")
         logger.debug(b, exc_info=True)
     logger.debug("Ending microphone stream")
     try:
         self._stream.stop_stream()
     except Exception as b:
         logger.warning("Failed to stop microphone stream")
         logger.debug(b, exc_info=True)
     logger.debug("Closing microphone stream")
     try:
         self._stream.close()
     except Exception as b:
         logger.warning("Failed to close microphone process")
         logger.debug(b, exc_info=True)
     self._p = None  # ; self._thread = None
     logger.debug("Microphone exited")
     logger.info("Terminated microphone.")
 def stream(self, n_milliseconds: int, video_path: str,
            timestamps_path: str) -> None:
     logger.info(
         "Camera will capture for {}ms. Starting!".format(n_milliseconds))
     cmd = self.build_cmd(n_milliseconds, video_path, timestamps_path)
     logger.info("Running {}".format(cmd))
     try:
         with open(self.stdout_path, 'a') as out:
             with open(self.stderr_path, 'a') as err:
                 subprocess.run(cmd, stdout=out, stderr=err)
     except Exception as e:
         logger.fatal("Failed running {}".format(self._stream_executable()))
         raise e
     logger.info("Camera finished capturing.")
Exemplo n.º 9
0
	def _arm(self) -> None:
		logger.info("Recording {} to {}".format(self.name(), self.output_path))
		make_dirs(dirname(self.output_path))
		self.log_file = open(self.output_path, 'a')
		self.log_file.write('Value,Time\n')
		self.activation_callback(self._record)