<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Playing wav files in Fire, UIFlow v1.13.8. It works.]]></title><description><![CDATA[<p dir="auto">It took many hours to get WAV files playing, so I though I would share my findings here.</p>
<p dir="auto"><strong>First</strong> the UIFlow UI does not show a "play WAV file" not in the SDCard section, the Speaker section, nor in the DAC section.</p>
<p dir="auto"><strong>Second</strong></p>
<pre><code>from wav import wav_player
wav_player.playWav('/sd/myfile.wav')
</code></pre>
<p dir="auto">fails with an <code>I2S does not have MODE_MASTER</code> error.</p>
<p dir="auto"><strong>Third</strong></p>
<pre><code>import machine
dac0 = machine.DAC(25)
dac0.wavplay('/sd/myfile.wav')
</code></pre>
<p dir="auto">does not work either, no sound is produced.</p>
<p dir="auto">However the similar (according to <a href="https://github.com/m5stack/M5Stack_MicroPython/blob/master/MicroPython_BUILD/components/micropython/esp32/machine_dac.c" target="_blank" rel="noopener noreferrer nofollow ugc">the code</a>)</p>
<pre><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)
</code></pre>
<p dir="auto">works fine. <strong>Finally !</strong></p>
<p dir="auto">If the sound file is big you can also use</p>
<pre><code>while True:
  data = ww.readframes(2048)
  if len(data) &gt; 0:
    dac_buffer = array.array("B", data)
    ret = dac0.write_buffer(dac_buffer, sample_rate, wait=True)
  else:
    break
</code></pre>
<p dir="auto">or similar (notice the difference in wait=False or True)</p>
<p dir="auto">I hope this helps future users.<br />
In the end <a href="https://github.com/m5stack/M5Stack_MicroPython/tree/master/MicroPython_BUILD/components/micropython/esp32" target="_blank" rel="noopener noreferrer nofollow ugc">digging into the code of what M5Stack provides</a> or not has been the best way to understand how to make the best out of the codebase.</p>
<p dir="auto">(could not use UIFlow 2 due to <a href="https://community.m5stack.com/topic/6887">SDCard issue</a>)</p>
]]></description><link>https://community.m5stack.com/topic/6893/playing-wav-files-in-fire-uiflow-v1-13-8-it-works</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 03:33:24 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6893.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Oct 2024 22:49:48 GMT</pubDate><ttl>60</ttl></channel></rss>