I need to make a app that visualizes audio data by graphing it, and I've tried
CodePudding user response:
It's a Uint8List
because that's a byte array and is what gets moved across the native-Dart boundary. So you need to view that byte array as a list of 16 bit integers. Use ByteBuffer
to do this.
final Uint8List data;
final pcm16 = data.buffer.asInt16List();
// pcm16 is an Int16List and will be half the length of data
// expect values in pcm16 to be between -32768 and 32767 so
// normalize by dividing by 32768.0 to get -1.0 to 1.0
You will probably find that you are getting twice as many bytes as you expect. If you are sampling at 16kHz, expect 32k bytes a second, but you'll get 16000 samples a second when viewed as 16 bit ints.