def is_audio(audio_pin_name): try: p = AudioOut(audio_pin_name) p.deinit() return True except ValueError: return False except RuntimeError: return False
# open the sample wav file with open(_icons[LOOP[CUR_LOOP_INDEX]][2], "rb") as wave_file: print("playing: {}".format(_icons[LOOP[CUR_LOOP_INDEX]][2])) # initialize audio output pin audio = AudioOut(board.AUDIO_OUT) # initialize WaveFile object wave = WaveFile(wave_file) # play it audio.play(wave) # while it's still playing while audio.playing: # update time variable _now = time.monotonic() # check for and process touch events check_for_touch(_now) # after done playing. deinit audio output audio.deinit() # increment index counter CUR_LOOP_INDEX = next_index() # update variable for last time we attempted to play sample LAST_PLAY_TIME = _now