![Adafruit UDA1334A Скачать руководство пользователя страница 31](http://html1.mh-extra.com/html/adafruit/uda1334a/uda1334a_manual_2845855031.webp)
def play_music(music_file):
'''
stream music with mixer.music module in blocking manner
this will stream the sound from disk while playing
'''
clock = pg.time.Clock()
try:
pg.mixer.music.load(music_file)
print("Music file {} loaded!".format(music_file))
except pygame.error:
print("File {} not found! {}".format(music_file, pg.get_error()))
return
pg.mixer.music.play()
# If you want to fade in the audio...
# for x in range(0,100):
# pg.mixer.music.set_volume(float(x)/100.0)
# time.sleep(.0075)
# # check if playback has finished
while pg.mixer.music.get_busy():
clock.tick(30)
freq = 44100 # audio CD quality
bitsize = -16 # unsigned 16 bit
channels = 2 # 1 is mono, 2 is stereo
buffer = 2048 # number of samples (experiment to get right sound)
pg.mixer.init(freq, bitsize, channels, buffer)
if len(sys.argv) > 1:
try:
user_volume = float(sys.argv[1])
except ValueError:
print "Volume argument invalid. Please use a float (0.0 - 1.0)"
pg.mixer.music.fadeout(1000)
pg.mixer.music.stop()
raise SystemExit
print("Playing at volume: " + str(user_ "\n")
pg.mixer.music.set_volume(user_volume)
mp3s = []
for file in os.listdir("."):
if file.endswith(".mp3"):
mp3s.append(file)
print mp3s
for x in mp3s:
try:
play_music(x)
time.sleep(.25)
except KeyboardInterrupt:
# if user hits Ctrl/C then exit
# (works only in console mode)
pg.mixer.music.fadeout(1000)
pg.mixer.music.stop()
© Adafruit Industries
https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a
Page 31 of 45
Содержание UDA1334A
Страница 1: ...Adafruit I2S Stereo Decoder UDA1334A Created by lady ada Last updated on 2019 01 30 06 56 56 PM UTC...
Страница 3: ...Adafruit Industries https learn adafruit com adafruit i2s stereo decoder uda1334a Page 3 of 45...
Страница 12: ...Adafruit Industries https learn adafruit com adafruit i2s stereo decoder uda1334a Page 12 of 45...