def _mic_level_watcher(self, bus, message, *args): structure = message.get_structure() peak = structure.get_value('peak')[0] self._log.info("Peak level %s", peak) if peak > SILENCE_DETECTION_RANGE[0] and not self.speaking_started: self.audio_from_mic = queue.Queue() self._log.info("Speaking started into queue %s", self.audio_from_mic) self.speaking_started = True if self._listening_timeout_timer: GObject.source_remove(self._listening_timeout_timer) self.speaking_finished_event = threading.Event() self.RecognizeCallback(self.audio_from_mic, self._mic_pipeline.dialogid, self.speaking_finished_event) if peak < SILENCE_DETECTION_RANGE[1] and self.speaking_started: self.silence_count += 1 if self.silence_count > 2: self._log.info("Speaking finished") self.speaking_started = False self.silence_count = 0 self._mic_pipeline.set_state(Gst.State.PAUSED) self.speaking_finished_event.set() aplay(ACK_BEEP, _bg=True) return True
def cancelListen(self): if self.speaking_started is False: self._log.info("Timed out listening") self._mic_pipeline.set_state(Gst.State.PAUSED) self._mic_pipeline.dialogid = None aplay(TIMEOUT_BEEP, _bg=True) return False
def run(self): global pid try: while True: if not os.path.isfile('/tmp/latest.wav'): sstv_debug_log('Player', '/tmp/latest.wav not found, continuing') continue sstv_debug_log('Player', 'Player reporting for duty') time.sleep(60) aplay('/tmp/latest.wav') except Exception as e: sstv_debug_log('Player', str(e), True) pass
def Listen(self, milliseconds=None, dialogid=None): success, state_micpipeline, pending = self._mic_pipeline.get_state(Gst.CLOCK_TIME_NONE) if state_micpipeline == Gst.State.PLAYING: self._log.info("Was already listening") aplay(TIMEOUT_BEEP, _bg=True) return False self._log.info("Starting listening, timeout milliseconds=%s, dialog=%s", milliseconds, dialogid) self.audio_pipeline.set_state(Gst.State.READY) self.audio_player.set_state(Gst.State.READY) self._waitForNothingPlaying() if milliseconds: self._listening_timeout_timer = GObject.timeout_add(milliseconds, self.cancelListen) aplay(LISTENING_BEEP, _bg=True) self._mic_pipeline.dialogid = dialogid self.speaking_started = False self.silence_count = 0 self._mic_pipeline.set_state(Gst.State.PLAYING)
def play_background(self): if platform == "darwin": cmd = f"-p {self.play_file} -r {self.rate} -d {self.dev}" self.process = sh.xplay(cmd.split(), _bg=True, _bg_exc=False) else: self.process = sh.aplay( f"{self.play_file} -r {self.rate} -D hw:{self.dev[0]},{self.dev[1]}" .split(), _bg=True, _bg_exc=False)
if chapter > 0: if VIDEO_PAUSED == True: omx_stdin.put('p') print("--- PLAY ---") time.sleep(.3) run_audio.kill() omx_stdin.put("\027[B") print('Rewind') time.sleep(1) if chapter > 1: print('sendOMX ' + repr(chapter)) omx_stdin.put(repr(chapter)) else: run_audio = aplay(AUDIO_NAME, _bg=True) VIDEO_PAUSED = False r_sensor_value = r_acc / NUM_CAMP i = 0 r_acc = 0 #print('R: ', r_sensor_value) if r_sensor_value >= R_SENSOR_MAX: if VIDEO_STARTED == False: print("Starting video...")
def play_sstv(): '''Play the SSTV file using aplay.''' aplay("latest.wav", _cwd=cwd)
try: if VIDEO_STARTED == False: if (not (GPIO.input(GPIO_PIN))): print("Starting video...") sendUDP('1') # open VIDEO_STARTED = True VIDEO_PAUSED = False time.sleep(.5) run = omxplayer('-s', VIDEO_NAME, _bg=True, _out=interact, _out_bufsize=250) time.sleep(1) run_audio = aplay(AUDIO_NAME, _bg=True) screen.fill((0, 0, 0)) pygame.display.update() else: # check if chapter button is pressed if omx_stdin: chapter = read_buttons() if chapter > 0: if VIDEO_PAUSED == True: omx_stdin.put('p') print("--- PLAY ---") time.sleep(.3)
def find_aplay_device(vendor_str_search="Adaptive"): aplay_out = sh.aplay("-l") return find_alsa_device(aplay_out, vendor_str_search)
def comm_to_user(message): fileToPlay = message + '.wav' sh.aplay("-Dhw:0,0", "--format=S16_LE", "--rate=44100", fileToPlay)
import sys import wave import getopt import sh if __name__ == "__main__": #riproduce un file che va bene come formato #(scheda,device) = (0,0), sample rate 44kHz, format S16_LE sh.aplay("-Dhw:0,0", "--format=S16_LE", "--rate=44100", "ANSWER.wav") def comm_to_user(message): fileToPlay = message + '.wav' sh.aplay("-Dhw:0,0", "--format=S16_LE", "--rate=44100", fileToPlay)
def Alarm(self): aplay(ALARM_BEEP, _bg=True)