def charge(): charged = False wave_charge_file = open(WAV_CHARGE, "rb") wave_charge = audioio.WaveFile(wave_charge_file) audio.play(wave_charge) while audio.playing: if not charged: for i in range(0, 100): r = int(i / 99 * NEOPIX_COLOUR[0]) g = int(i / 99 * NEOPIX_COLOUR[1]) b = int(i / 99 * NEOPIX_COLOUR[2]) strip.fill((r, g, b)) Nixie2.set_digit(i % 10) Nixie1.set_digit(int(i / 10)) time.sleep(0.005) if i == 99: charged = True if switch.value: break if switch.value: audio.stop() break wave_charged_file = open(WAV_CHARGED, "rb") wave_charged = audioio.WaveFile(wave_charged_file) while not switch.value: audio.play(wave_charged) while audio.playing: strip.fill(tuple(NEOPIX_COLOUR)) if switch.value: audio.stop() break fire()
def sort(num): if (sum(code_list) <= 2): if ana_val > no_pressure: #sip code_list[0] += 1 if ana_val < no_pressure: #puff code_list[1] += 1 if ana_val == no_pressure: pass else: print(code_list) code_val = tuple(code_list) word = (d.get(code_val)) if word in d.values(): print(word) wave_file = open(word, "rb") wave = audioio.WaveFile(wave_file) audio.play(wave) time.sleep(0.5) else: pass code_list[0] = 0 code_list[1] = 0 time.sleep(0.5)
def play_sound(self, filename, *, wait_to_finish=True, loop=False): """Play a sound :param filename: The filename of the sound to play :param wait_to_finish: Whether playing the sound should block :param loop: Whether the sound should loop """ self._speaker_enable.value = False self.audio.stop() if self._wavfile: self._wavfile.close() self._wavfile = None if not filename: return # nothing more to do, just stopped filename = self._gamedirectory + "/" + filename print("Playing sound", filename) board.DISPLAY.wait_for_frame() try: self._wavfile = open(filename, "rb") except OSError: raise OSError("Could not locate sound file", filename) wavedata = audioio.WaveFile(self._wavfile) self._speaker_enable.value = True self.audio.play(wavedata, loop=loop) if loop or not wait_to_finish: return while self.audio.playing: pass self._wavfile.close() self._wavfile = None self._speaker_enable.value = False
def play_file(self, file_name): """ Play a .wav file using the onboard speaker. :param file_name: The name of your .wav file in quotation marks including .wav .. image :: ../docs/_static/speaker.jpg :alt: Onboard speaker .. code-block:: python from adafruit_circuitplayground.express import cpx while True: if cpx.button_a: cpx.play_file("laugh.wav") elif cpx.button_b: cpx.play_file("rimshot.wav") """ # Play a specified file. self.stop_tone() self._speaker_enable.value = True if sys.implementation.version[0] >= 3: with audioio.AudioOut(board.SPEAKER) as audio: wavefile = audioio.WaveFile(open(file_name, "rb")) audio.play(wavefile) while audio.playing: pass else: raise NotImplementedError("Please use CircuitPython 3.0 or higher.") self._speaker_enable.value = False
def play_waves(file_num): wave_file = open(wave_files[file_num], "rb") # open a wav file wave = audioio.WaveFile(wave_file) audio.play(wave) # play the wave file while audio.playing: # allow the wav to finish playing pass wave_file.close() # close the wav file
def play_wave(filename): wave_file = open(filename, "rb") wave = audioio.WaveFile(wave_file) audio.play(wave) while audio.playing: pass wave_file.close()
def play_sound(file_name): board.DISPLAY.wait_for_frame() wavfile = open(file_name, "rb") wavedata = audioio.WaveFile(wavfile) speaker_enable.value = True audio.play(wavedata) return wavfile
def play_file(filename): wave_file = open(filename, 'rb') with audioio.WaveFile(wave_file) as wave: with audioio.AudioOut(board.A0) as audio: audio.play(wave) while audio.playing: pass
def play_file(self, file_name): #self._speaker_enable.value = True with audioio.AudioOut(board.AUDIO_OUT) as audio: with open(file_name, "rb") as f: with audioio.WaveFile(f) as wavefile: audio.play(wavefile) while audio.playing: pass
def play_file(wavfile): wavfile = "/numbers/" + wavfile print("Playing", wavfile) with open(wavfile, "rb") as f: wav = audioio.WaveFile(f) aout.play(wav) while aout.playing: pass
def play_file(filename): wave_file = open(filename, "rb") with audioio.WaveFile(wave_file) as wave: with audioio.AudioOut(board.A0) as audio: print("playing %s" % filename) audio.play(wave) while audio.playing: pass
def play_message(self): with open(self.audio_file, "rb") as f: wav_file = audioio.WaveFile(f) audio = audioio.AudioOut(board.A0) audio.play(wav_file) while audio.playing: pass
def play_wav(name, loop=False): print("playing", name) try: wave_file = open(name + '.wav', 'rb') wave = audioio.WaveFile(wave_file) audio.play(wave, loop=loop) except: return
def fire(): wave_file = open(WAV_FIRE, "rb") wave = audioio.WaveFile(wave_file) audio.play(wave) while audio.playing: pixels[1] = NEOPIX_COLOUR_BARREL pixels[1] = NEOPIX_OFF time.sleep(1)
def load_wav(name): """ Load a WAV audio file into RAM. @param name: partial file name string, complete name will be built on this, e.g. passing 'foo' will load file 'foo.wav'. @return WAV buffer that can be passed to play_wav() below. """ return audioio.WaveFile(open(name + '.wav', 'rb'))
def play_audio(wavfile): f = open(wavfile, "rb") wav = audioio.WaveFile(f) a.play(wav) while a.playing: pass f.close() gc.collect()
def play_audio(): amp_enable.value = True wave_file = open(wav_file_options[randint(0, len(wav_file_options) - 1)], "rb") wave = audioio.WaveFile(wave_file) tip_detected = False audio.play(wave)
def play_file(wavfile): print("Playing", wavfile) with open(wavfile, "rb") as f: wav = audioio.WaveFile(f) AUDIO.play(wav) while AUDIO.playing: LED.duty_cycle = random.randint(5000, 30000) time.sleep(0.1) LED.duty_cycle = 65535
def play_file(filename): global audio_file # pylint: disable=global-statement if gc_audio.playing: gc_audio.stop() if audio_file: audio_file.close() audio_file = open(filename, "rb") wav = audioio.WaveFile(audio_file) gc_audio.play(wav)
def play_file(wavfile): with open(wavfile, "rb") as file: wavf = audioio.WaveFile(file) a.play(wavf) while a.playing: servos[1].angle = MOUTH_START time.sleep(.2) servos[1].angle = MOUTH_END time.sleep(.2)
def play_file(playname): print("Playing File " + playname) wave_file = open(playname, "rb") with audioio.WaveFile(wave_file) as wave: with audioio.AudioOut(board.A0) as audio: audio.play(wave) while audio.playing: simpleCircle(.02) print("finished")
def play_sound_file(file_path): try: with open(file_path, "rb") as f: wave = audioio.WaveFile(f) audio.play(wave) while audio.playing: time.sleep(0.005) except OSError as e: print('Error opening file: %s' % e)
def play_file(filename): print("Playing file: " + filename) wave_file = open(filename, "rb") with audioio.WaveFile(wave_file) as wave: with audioio.AudioOut(board.A0) as audio: audio.play(wave) while audio.playing: pass print("Finished")
def play(self, audio_file, loop=False): """ Start playing an open file ``audio_file``. If ``loop`` is ``True``, repeat until stopped. This function doesn't block, the sound is played in the background. """ self.stop() wave = audioio.WaveFile(audio_file) self.audio.play(wave, loop=loop)
def play_file(audio_filename): global audio_file # pylint: disable=global-statement if myaudio.playing: myaudio.stop() if audio_file: audio_file.close() audio_file = open("/sounds/" + audio_filename, "rb") wav = audioio.WaveFile(audio_file) print("Playing " + audio_filename + ".") myaudio.play(wav)
def play_file(wavfile): print("Playing", wavfile) with open(wavfile, "rb") as f: wav = audioio.WaveFile(f) a.play(wav) while a.playing: # turn servos, motors, etc. during playback mouth_servo.angle = MOUTH_END time.sleep(0.15) mouth_servo.angle = MOUTH_START time.sleep(0.15)
def play_file(wavfile): print("Playing", wavfile) with open(wavfile, "rb") as f: wav = audioio.WaveFile(f) a.play(wav) while a.playing: my_servo.angle = MOUTH_END time.sleep(0.15) my_servo.angle = MOUTH_START time.sleep(0.15)
def play_file(wavfile): print("Playing scream!") with open(wavfile, "rb") as f: wav = audioio.WaveFile(f) a.play(wav) while a.playing: head_servo.angle = 60 time.sleep(.01) head_servo.angle = 120 time.sleep(.01)
def play_wave(): wave_file = open("hiss01.wav", "rb") # open a wav file wave = audioio.WaveFile(wave_file) audio.play(wave) # play the wave file led.value = True servo_release() print('Motion detected!') while audio.playing: # turn on LED, turn servo pass wave_file.close() # close the wav file
def note_on(self, key, velocity): fname = self._samples[key] if fname is not None: f = open(SAMPLE_FOLDER + fname, 'rb') wav = audioio.WaveFile(f) voice = self._find_usable_voice_for(key) if voice is not None: voice['key'] = key voice['file'] = f self._mixer.play(wav, voice=voice['voice'], loop=False)