Hi,
when using openMV DAC to play wav file, MemoryError exception is raised in chunk.py when readframes function in wave.py module is called.
I got the chunk.py and wave.py and test wav file from below article:
https://docs.micropython.org/en/latest/ ... _skin.html
the tested wave file is near 9KB, 8-bit, 16KHZ.
def play(filename):
f = wave.open(filename, 'r')
total_frames = f.getnframes()
framerate = f.getframerate()
for position in range(0, total_frames, framerate):
f.setpos(position)
dac.write_timed(f.readframes(framerate), framerate)
delay(1000)
Is this MemoryError due to limited heap size? how to check how much heap available? the tested wav file is less than 9kB.
is there anyone succeed in play wav file with openMV?
Thanks,
MemoryError when read wave frames
Re: MemoryError when read wave frames
Hi, I see no reason why this doesn't work. However, we've never tested this.
Can you give use the exact line of code that error happened on?
Can you give use the exact line of code that error happened on?
Nyamekye,
Re: MemoryError when read wave frames
Please see the attached screenshot.
Thanks,
Thanks,
- Attachments
-
- exception.png (35.23 KiB) Viewed 3000 times
-Falong
- iabdalkader
- Posts: 1292
- Joined: Sun May 24, 2015 3:53 pm
Re: MemoryError when read wave frames
import gc
print("Free: %dKBs"%(gc.mem_free()//1024))
Note memory could be fragmented.
Please share the whole script(s)+wave file(s) in a .zip and I'll test them.
Re: MemoryError when read wave frames
Can you please leave me your mail address, I'll mail you the script.
Also find when wav file is very small(tested with 1KB), it is ok.
Thanks,
Also find when wav file is very small(tested with 1KB), it is ok.
Thanks,
-Falong
- iabdalkader
- Posts: 1292
- Joined: Sun May 24, 2015 3:53 pm
Re: MemoryError when read wave frames
This is just a fragmented memory issue, the scripts run fine on H7. I think most of memory is consumed by just loading/parsing/compiling the modules wave and chunk.
This seems to fix it:
This seems to fix it:
Code: Select all
frames = f.readframes(frame_rate)
self.dac.write_timed(frames, frame_rate)
del frames
delay(1000)
gc.collect()
Re: MemoryError when read wave frames
Just tested, it seems not fix my issue on M7. do you have an estimate of memory cost of openmv itself excluding framebuffer?iabdalkader wrote: ↑Sat Jun 09, 2018 4:14 pmThis is just a fragmented memory issue, the scripts run fine on H7. I think most of memory is consumed by just loading/parsing/compiling the modules wave and chunk.
This seems to fix it:Code: Select all
frames = f.readframes(frame_rate) self.dac.write_timed(frames, frame_rate) del frames delay(1000) gc.collect()
Thanks
-Falong
- iabdalkader
- Posts: 1292
- Joined: Sun May 24, 2015 3:53 pm
Re: MemoryError when read wave frames
Hi,
Add a gc.collect at the end of detect_face_image:
Code: Select all
self.check_head_sideway(rotate_angle)
gc.collect()
Code: Select all
gc.collect()
frames = f.readframes(frame_rate)
self.dac.write_timed(frames, frame_rate)
del frames
gc.collect()
print("Free: %dKBs"%(gc.mem_free()/1024))
Return to “Technical Discussion”
Who is online
Users browsing this forum: No registered users and 1 guest