Playing wav files in Fire, UIFlow v1.13.8. It works.
-
It took many hours to get WAV files playing, so I though I would share my findings here.
First the UIFlow UI does not show a "play WAV file" not in the SDCard section, the Speaker section, nor in the DAC section.
Second
from wav import wav_player wav_player.playWav('/sd/myfile.wav')
fails with an
I2S does not have MODE_MASTER
error.Third
import machine dac0 = machine.DAC(25) dac0.wavplay('/sd/myfile.wav')
does not work either, no sound is produced.
However the similar (according to the code)
from wav import wav ww = wave.open('/sd/myfile.wav') sample_rate = ww.getframerate() # read all data, play in background data = ww.readframes(ww.getnframes()) dac_buffer = array.array("B", data) ret = dac0.write_buffer(dac_buffer, sample_rate, wait=False)
works fine. Finally !
If the sound file is big you can also use
while True: data = ww.readframes(2048) if len(data) > 0: dac_buffer = array.array("B", data) ret = dac0.write_buffer(dac_buffer, sample_rate, wait=True) else: break
or similar (notice the difference in wait=False or True)
I hope this helps future users.
In the end digging into the code of what M5Stack provides or not has been the best way to understand how to make the best out of the codebase.(could not use UIFlow 2 due to SDCard issue)