examples icon indicating copy to clipboard operation
examples copied to clipboard

Updated AudioInputManager and ViewController to read audio data appro…

Open thumbarnirmal opened this issue 3 years ago • 6 comments

…priate to the iOS documentation

thumbarnirmal avatar May 09 '22 11:05 thumbarnirmal

Now cant import anything it's showing "PortAudio library not found" error while importing

Sanjay2802 avatar May 14 '22 18:05 Sanjay2802

Now cant import anything it's showing "PortAudio library not found" error while importing

Hi @Sanjay2802, is this occurring on the following branch from which I have raised PR? branch - thumbarnirmal:master

thumbarnirmal avatar May 15 '22 16:05 thumbarnirmal

Noo , i suppose

Sanjay2802 avatar May 15 '22 17:05 Sanjay2802

@thumbarnirmal Could you clarify what's the issue with the current code?

@Sanjay2802 The PortAudio library not found error occurs in Python's tflite-support package v0.4.0 on Linux. You can fix it by either:

  • Run sudo apt-get install libportaudio2
  • Use the nightly build of tflite-support (pip install tflite-support-nightly). The error is already fixed in master branch and will be release in the next version of tflite-support.

khanhlvg avatar May 16 '22 06:05 khanhlvg

Hi @khanhlvg

The inputNode.installTap callback in AudioInputManager.swift file returns audio data in range of [100, 400] milliseconds. This is specified in the iOS documentation which can be checked in xcode. It is not specified in apple developer docs website.

When the audio data returned by installTap callback is converted and saved in pcmBuffer, the pcmBuffer will have only 400 ms of unique data. The same audio data is repeated to fill the pcmBuffer for 1 second. This can be checked by trying to match pcmBuffer array from index[0:399] and index[400:799].

Above explanation is based on the assumption that inputNode.installTap has buffersize which is greater than or equal to 400 ms. If, for example, buffer size is equivalent to 200 ms, same issue would occur, but data would repeat in pcmBuffer from index 200, 400 and so on.

thumbarnirmal avatar May 16 '22 07:05 thumbarnirmal

When the audio data returned by installTap callback is converted and saved in pcmBuffer, the pcmBuffer will have only 400 ms of unique data. The same audio data is repeated to fill the pcmBuffer for 1 second. This can be checked by trying to match pcmBuffer array from index[0:399] and index[400:799].

For sake of brevity, I have mentioned time in milliseconds as indexing value in array. Actual array index would be calculated by multiplying the pcmBuffer's sampling rate with the time value in seconds.

thumbarnirmal avatar May 17 '22 05:05 thumbarnirmal