[M5 Fire] Wave playing?
inrepublica last edited by
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.
IAMLIUBO last edited by
Hi, @inrepublica ,
Sorry about that,try "from wav import wave".
inrepublica last edited by
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'
has anyone tried to run this on a core2 ?
I get errors when trying to initialize i2s device:
"type object 'I2S' has no attribute MODE:MASTER....
Have you updated to the latest UIFLow firmware?
You are replying to old topics and the firmware has changed quite a bit since.
@ajb2k3 Yes, I updated to the latest firmware.
I know, it's an old topic, but I made a new one, about playing audio to external speakers but nobody replied :(
So I am trying to figure what people did before me.
I have got a wave file to play on the core2 in UIFlow but I found a bug with one of the blocks.
I just used the Play local file block which played a file stored in memory.
If your trying from the SD card the documents say the path is sd/somefile.wav not /sd/somefile.wav (no preceding forward slash)
however this assumes that somefile.wav is stored in the root of the SD card. also the wav file has to match certain file requirements that are a restriction of MicroPython.
@ajb2k3 thanks for your reply. Yeah, I figured out the same thing with the file path on the core2 and it plays wavs quite reliably through the speaker.... however, this speaker is quite low volume and in my setup it has to give voice commands to an ipad (in an art exhibition)... so I need to connect to an external speaker.
Do you happen to know how I can route the wav-audio to the DAC (pin 25) on the core2?
any suggestions what to do?
I know the ESP32 supports I2S (audio) output but have no idea how so setup and use I2S.
@ajb2k3 ok, I see. But thanks for your reply. I post in this forum if I can figure it out