🤖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.

    Scheduled Pinned Locked Moved M5Stack Fire
    1 Posts 1 Posters 1.6k Views
    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 Offline
      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

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • First post
        Last post