Code: Select all
import time
import array
import math
import audioio
import board
import audiobusio
import busio, storage, os, adafruit_sdcard, digitalio
spi = busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO)
cs = digitalio.DigitalInOut(board.SD_CS)
sd = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sd)
storage.mount(vfs, '/sd')
with open('/sd/sweetiepie.wav', 'rb') as sound:
sfx = audioio.WaveFile(sound)
# For Grand Central M4
audio = audiobusio.I2SOut(board.D14, board.D33, board.D32)
while True:
audio.play(sfx)
while audio.playing:
pass
However when I try to use the same wav file stored on the SD card, it plays back with significant distortion and at about 80% speed.
Is there a way to read and play wav files directly from the SD card?