fftea icon indicating copy to clipboard operation
fftea copied to clipboard

How do I convert the raw data obtained by the microphone into the data required for the spectrogram?

Open tang158152 opened this issue 1 year ago • 10 comments

截屏2024-08-21 14 16 40

tang158152 avatar Aug 21 '24 16:08 tang158152

How do I convert the raw data obtained by the microphone into the data required for the spectrogram? I don't know much about audio, please forgive me

tang158152 avatar Aug 21 '24 16:08 tang158152

Need some details about what the raw data looks like. What is the Dart type? How is it encoded?

Assuming it's just, say, an Int16List, you just need to convert it to a List<double> or Float64List by mapping the int16 range (-32768 to 32767) to the usual range for float audio sample (-1 to 1). Ie, just divide each element by 32768.

Also, my experience with microphone libraries in flutter has been pretty bad. I'd recommend verifying the data you're getting from the microphone by saving it to a file and listening back to it, before you try to run it through a spectrogram. See this comment.

liamappelbe avatar Aug 22 '24 00:08 liamappelbe

Need some details about what the raw data looks like. What is the Dart type? How is it encoded?

Assuming it's just, say, an Int16List, you just need to convert it to a List<double> or Float64List by mapping the int16 range (-32768 to 32767) to the usual range for float audio sample (-1 to 1). Ie, just divide each element by 32768.

Also, my experience with microphone libraries in flutter has been pretty bad. I'd recommend verifying the data you're getting from the microphone by saving it to a file and listening back to it, before you try to run it through a spectrogram. See this comment.

Mine is a audio_streamer plug-in, I see that the data is sent every 0.5, 19200 data is delivered at a time, this is the data issued every 0.5 seconds, can you see the details of these raw data Uploading data.txt…

tang158152 avatar Aug 22 '24 03:08 tang158152

And I pay attention to the big, in this 19,200 data, the previous data is always large

tang158152 avatar Aug 22 '24 03:08 tang158152

You upload hasn't worked, so I can't actually see the data. It looks like the audio_streamer plugin already gives you a List<double>, so you probably don't actually need to do any conversions.

Since you want to stream the data, use STFT.stream, and it should all just work.

I still recommend saving a few of the chunks you get from audio_streamer to a WAV file, and listening to the WAV to make sure there are no audio artifacts that would mess up the STFT.

liamappelbe avatar Aug 22 '24 03:08 liamappelbe

data.txt

tang158152 avatar Aug 22 '24 03:08 tang158152

数据.txt

This is data acquired every 0.5 seconds

tang158152 avatar Aug 22 '24 03:08 tang158152

yep, looks like it's already in the correct format. Have you tried running it through STFT.stream?

liamappelbe avatar Aug 22 '24 03:08 liamappelbe

STFT.stream

Is there a suitable plugin library for STFT.stream, I don't know much about audio

tang158152 avatar Aug 22 '24 03:08 tang158152

Is there a suitable plugin library for STFT.stream, I don't know much about audio

Not sure what you mean. You can use this package anywhere you'd want to use a plugin. package:fftea is pure Dart, so it's fully compatible with all Flutter platforms. No plugin needed.

liamappelbe avatar Aug 22 '24 03:08 liamappelbe