Skip to content

Commit 7cc37c3

Browse files
authored
Merge pull request #2390 from jedgarpark/see-n-say
first commit see n say code
2 parents 85e2c3e + 73cc779 commit 7cc37c3

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

See_N_Say/code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-FileCopyrightText: 2023 John Park for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import os
6+
import audiocore
7+
import board
8+
import audiobusio
9+
import audiomixer
10+
from digitalio import DigitalInOut, Pull
11+
from adafruit_debouncer import Button
12+
13+
button_pins = (
14+
board.D2, board.D3, board.D4, board.D5,
15+
board.D6, board.D7, board.D8, board.D9,
16+
board.D10, board.MOSI, board.MISO, board.SCK,
17+
)
18+
buttons = [] # will hold list of Debouncer button objects
19+
for pin in button_pins: # set up each pin
20+
tmp_pin = DigitalInOut(pin) # defaults to input
21+
tmp_pin.pull = Pull.UP # turn on internal pull-down resistor
22+
buttons.append(Button(tmp_pin, value_when_pressed=False))
23+
24+
# get the filenames in aplha order from files in the 'wavs' directory
25+
sounds = []
26+
for filename in sorted(os.listdir("/wavs")):
27+
filename = filename.lower()
28+
if filename.endswith(".wav") and not filename.startswith("."):
29+
sounds.append(filename)
30+
31+
audio = audiobusio.I2SOut(bit_clock=board.A1, word_select=board.A2, data=board.A3)
32+
mixer = audiomixer.Mixer(voice_count=1, sample_rate=11025, channel_count=1,
33+
bits_per_sample=16, samples_signed=True)
34+
35+
audio.play(mixer)
36+
mixer.voice[0].level = 0.5
37+
38+
def play_sound(sound_number):
39+
wave_file = open(("wavs/" + sounds[sound_number]), "rb")
40+
wave = audiocore.WaveFile(wave_file)
41+
mixer.voice[0].play(wave, loop=False)
42+
43+
44+
while True:
45+
for i in range(len(buttons)):
46+
buttons[i].update()
47+
if buttons[i].pressed:
48+
play_sound(i)

0 commit comments

Comments
 (0)