0

im trying to create a voice recorder using max9814 and raspberry pi pico with circuitpython/micropython and my problem is when it saves the recordings on .wav file some parts of the audio loses because the whole process is running on a core and I'm looking for a way to handle the recording and saving part on separated cores is there anyway to do that?

My code is below.

import board
import analogio
import time
import adafruit_wave
import struct
import storage

# storage.remount("/", readonly=False)

adc = analogio.AnalogIn(board.A0)
conversion_factor = 3.3/4096
buffer = []

f = adafruit_wave.open("audio.wav", "w")
f.setnchannels(1)
f.setsampwidth(2)
f.setframerate(8000)

def save(data):
    global f
    f.writeframes(bytearray(data))
    print("done")

try:
    while True:
        sample = adc.value * conversion_factor
        frame = bytearray(struct.pack('>H', int(sample)))
        buffer.extend(frame)
        
        if len(buffer) > 16000:
            save(buffer)
            buffer = []
            print("clear buffer")
except KeyboardInterrupt:
    print("closing")
    f.close()

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.