🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Playing wav files in Fire, UIFlow v1.13.8. It works.

    M5Stack Fire
    1
    1
    264
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rodrigob
      last edited by

      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)

      1 Reply Last reply Reply Quote 0
      • First post
        Last post