I'm trying to listen to micrphone stream and finding the scale of the audio being read by the stream. I'm using mic_stream package for my flutter project, and need to understand how to find the frequency of the audio and then find the scale of the microphone's audio.
Here's my code. It currently displays the
- length of the Stream List of int values created every second
- The total of stream list added via the reduce (a+b) function
- The total divided by a numerical formula that I found online.
I learnt that the scale can be found by finding the frequency of an audio, and then matching that frequency to a given table. That's why I tried listening to the microphone audio and finding the frequency. I'm still not sure about this method because both the frequency sample rate formulas are displaying the same range of integer values.
The length remains the 8192 for all audio streams.
The total sum is displayed within 90-106 range.
and the total divided by formula is displayed within 0.0013-0.0019 range. The range remains the same with any song I play. Changes within a second.
Future<bool> _startListening() async { MicStream.shouldRequestPermission(true); stream = await MicStream.microphone( audioSource: AudioSource.DEFAULT, sampleRate: 48000, channelConfig: ChannelConfig.CHANNEL_IN_MONO, audioFormat: AudioFormat.ENCODING_PCM_16BIT); print( "Start Listening to the microphone, sample rate is ${await MicStream.sampleRate}, bit depth is ${await MicStream.bitDepth}, bufferSize: ${await MicStream.bufferSize}"); bytesPerSample = (await MicStream.bitDepth)! ~/ 8; samplesPerSecond = (await MicStream.sampleRate)!.toInt(); localMax = null; localMin = null; setState(() { _frequency = samplesPerSecond; isRecording = true; startTime = DateTime.now(); }); visibleSamples = []; listener = stream!.listen(_calculateSamples); StreamSubscription<List<int>> _listener = stream!.listen((samples) => _textFrequency = [ 'Total: ${samples.length}', 'Added: ${samples.reduce((a, b) => a + b)}', 'Added Frequency: ${int.parse(samples.reduce((a, b) => a + b).toString()) / (65536 * 10000)}' ].toString()); return true; }