Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this package take a list of ADC values and convert it to an audio file? #397

Open
gabemorris12 opened this issue Jul 14, 2023 · 3 comments

Comments

@gabemorris12
Copy link

I have a simple question and would like to come to an understanding to see if my plan will work. I am looking to use a Raspberry Pi Pico to get ADC data from this electret microphone device. I plan to capture this ADC data with a known sampling rate and send it to a computer, so that I can use this package to convert the data into an audio file.

So the computer script would look something like this:

import soundfile as sf

# Use some communication method with the Pico to get a list of ADC values
data = []  # list of ADC values from 0 to 65535

sf.write("audio.wav", data, samplerate=44100)

I am wondering if this will work or if there is something more. I read in the docs that a one dimensional data list can create a mono file, but I am not sure what that means. Could someone provide some feedback on this topic? Will it work as is?

@bastibe
Copy link
Owner

bastibe commented Jul 15, 2023

It will work, but you will have to set the data format manually, probably format='RAW' and subtype='PCM_16', and you need to supply the data as an int16 numpy array, and shift the values to go from -32768...32767 instead of 0...65536 (numpy.asarray(numpy.array(data) - 2**16), dtype='int16') should do the trick).

@RonaldAJ
Copy link

@bastibe Are you sure? The RP Pico is a microcontroller which runs micropython.

On the ARM cortex RPi's I can confirm that you can save sound using soundfile.

@gabemorris12
Copy link
Author

@bastibe I appreciate the response, and I'll be sure to give this a try in the coming weeks!

@RonaldAJ I'm using the Raspberry Pi Pico just as a means of getting data. Soundfile will be used on a windows 10 computer or a Linux based Rapberry Pi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants