def _initialize_audio(self): if self._audio is None: self._audio = audioio.AudioOut(board.A1) self._mixer = audiomixer.Mixer(voice_count=VOICE_COUNT, sample_rate=16000, channel_count=1, bits_per_sample=16, samples_signed=True) self._audio.play(self._mixer)
sample_rate = wav.sample_rate print('%d channels, %d bits per sample, %d Hz sample rate ' % (wav.channel_count, wav.bits_per_sample, wav.sample_rate)) # Audio playback object - we'll go with either mono or stereo depending on # what we see in the first file if wav.channel_count == 1: audio = audioio.AudioOut(board.A1) elif wav.channel_count == 2: audio = audioio.AudioOut(board.A1, right_channel=board.A0) else: raise RuntimeError('Must be mono or stereo waves!') mixer = audiomixer.Mixer(voice_count=2, sample_rate=sample_rate, channel_count=channel_count, bits_per_sample=bits_per_sample, samples_signed=True) audio.play(mixer) # Clear all pixels trellis.pixels.fill(0) # Light up button with a valid sound file attached for i, v in enumerate(SAMPLES): filename = SAMPLE_FOLDER + v[0] try: with open(filename, 'rb') as f: wav = audiocore.WaveFile(f) print( filename,
alt_button = DigitalInOut(board.A5) alt_button.switch_to_input(pull=Pull.UP) # ---ACCELEROMETER SETUP--- # Set up accelerometer on I2C bus, 4G range: i2c = busio.I2C(board.SCL, board.SDA) int1 = DigitalInOut(board.D6) accel = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) # ---SPEAKER SETUP--- enable = DigitalInOut(board.D10) enable.direction = Direction.OUTPUT enable.value = True # Set up speakers and mixer. Stereo files, where music has empty right channel, FX empty left speaker = audioio.AudioOut(board.A0, right_channel=board.A1) mixer = audiomixer.Mixer(channel_count=2, buffer_size=2304, sample_rate=22050) # ---NEOPIXEL SETUP--- pixel_pin = board.D5 pixel_num = 154 pixels = neopixel.NeoPixel( pixel_pin, pixel_num, brightness=0.6, auto_write=False, pixel_order=neopixel.GRBW ) # ^ change pixel_order depending on RGB vs. RGBW pixels # ---Pixel Map--- # this is the physical order in which the strips are plugged pixel_stripA = PixelSubset(pixels, 0, 18) # 18 pixel strip pixel_stripB = PixelSubset(pixels, 18, 36) # 18 pixel strip pixel_jewel = PixelSubset(pixels, 36, 43) # 7 pixel jewel
button_tones = [ "dtmf/tt_1.wav", "dtmf/tt_2.wav", "dtmf/tt_3.wav", "dtmf/tt_4.wav", "dtmf/tt_5.wav", "dtmf/tt_6.wav", "dtmf/tt_7.wav", "dtmf/tt_8.wav", "dtmf/tt_9.wav", "dtmf/tt_star.wav", "dtmf/tt_0.wav", "dtmf/tt_pound.wav" ] digits_entered = 0 # counter dialed = [] # list of digits user enters to make one 7 digit number dialed_str = "" # stores the phone number string for dictionary comparison audio = AudioOut(board.TX) # PWM out pin mixer = audiomixer.Mixer( voice_count=4, sample_rate=22050, channel_count=1, bits_per_sample=16, samples_signed=True, ) audio.play(mixer) mixer.voice[0].level = 1.0 # dial tone voice mixer.voice[1].level = 1.0 # touch tone voice mixer.voice[2].level = 0.0 # song/message voice mixer.voice[3].level = 0.0 # busy signal wave_file0 = open(dial_tone, "rb") wave0 = WaveFile(wave_file0) mixer.voice[0].play(wave0, loop=True) # play dial tone wave_file2 = open(wrong_number, "rb") wave2 = WaveFile(wave_file2)
with open(VOICES[0], "rb") as f: wav = audiocore.WaveFile(f) print("%d channels, %d bits per sample, %d Hz sample rate " % (wav.channel_count, wav.bits_per_sample, wav.sample_rate)) # Audio playback object - we'll go with either mono or stereo depending on # what we see in the first file if wav.channel_count == 1: audio = audioio.AudioOut(board.A1) elif wav.channel_count == 2: audio = audioio.AudioOut(board.A1, right_channel=board.A0) else: raise RuntimeError("Must be mono or stereo waves!") mixer = audiomixer.Mixer(voice_count=4, sample_rate=wav.sample_rate, channel_count=wav.channel_count, bits_per_sample=wav.bits_per_sample, samples_signed=True) audio.play(mixer) samples = [] # Read the 4 wave files, convert to stereo samples, and store # (show load status on neopixels and play audio once loaded too!) for v in range(4): trellis.pixels[(v, 0)] = DRUM_COLOR[v] wave_file = open(VOICES[v], "rb") # OK we managed to open the wave OK for x in range(1, 4): trellis.pixels[(v, x)] = DRUM_COLOR[v] sample = audiocore.WaveFile(wave_file) # debug play back on load!