[M5 Fire] Wave playing?



  • Hi all,

    I try to follow this tutorial to play wav file on M5stack Fire: https://m5stack.hackster.io/lukasmaximus89/m5stack-rfid-face-wav-playing-flashcard-program-526cb5

    But I have a little problem with the module wave. When i run my micropython code i have an error on the fire:

    no module named 'wave'
    

    Thanks for your help.



  • Hi, @inrepublica ,
    Sorry about that,try "from wav import wave".



  • Thanks for your reply, when i test this code in UIFlow 1.7.7 on Fire:

    from machine import I2S
    import os, uos
    from wav import wave
    
    #initialize the I2S device
    i2s = I2S(  mode = I2S.MODE_MASTER | I2S.MODE_TX | I2S.MODE_DAC_BUILT_IN,
                rate = 16000,
                bits = 16,
                channel_format = I2S.CHANNEL_ONLY_RIGHT,
                data_format = I2S.FORMAT_I2S_MSB)
    
    #uncomment the following line if you have issues mounting the sd
    #uos.sdconfig(uos.SDMODE_SPI,clk=18,mosi=23,miso=19,cs=4)
    
    #create a function to play the wav
    def wav_player(fname):
        wav = wave.open(fname)
        i2s.set_dac_mode(I2S.DAC_RIGHT_EN)
        i2s.sample_rate(wav.getframerate())
        i2s.bits(wav.getsampwidth() * 8)
        i2s.nchannels(wav.getnchannels())
        i2s.volume(20)
    
        while True:
            data = wav.readframes(1024)
            if len(data) > 0:
                i2s.write(data)
            else:
                wav.close()
                break
    
    # Playing WAV audio file
    lcd.clear()
    lcd.print('working',0,0,0xffffff)
    
    try:
        uos.mountsd()
    except:
        os.mountsd()
        lcd.print('sd card not mounted',0,50,0xffffff)
        pass
    
    while True:
            wav_player('/sd/test.wav')
            i2s.stop()
            wait(5)
    

    I have another error on line 39:

    module object has no attribute 'mountSD'