flutter_sound icon indicating copy to clipboard operation
flutter_sound copied to clipboard

[HELP] iOS Stream recording update frequency

Open mowgliho opened this issue 3 years ago • 1 comments

Flutter Sound Version :

8.3.12

Severity

  • Crash: No

  • Result is not what expected: Yes

  • Cannot build my App: can build

  • Minor issue: no, as real-time feedback is crucial to me

Platforms you faced the error

iOS(emulator (iPhone8, iOS15.2), and real device (iPhone10))

Description

Hello,

I'm writing an app that aims to provide feedback to user audio input in real time. Things work great in Android, but when I run it in iOS, the stream I'm listening too only gets updated every 0.4 seconds or so. Is it possible to increase the frequency of audio data updates?

Reproduce

This also happens with the flutter_sound demo, and can be easily seen by replacing lines 359-365 of demo.dart with:

   recordingDataController = StreamController<Food>();
    int lastTime = DateTime.now().millisecondsSinceEpoch;
    _recordingDataSubscription =
        recordingDataController!.stream.listen((buffer) {
      if (buffer is FoodData) {
        int now = DateTime.now().millisecondsSinceEpoch;
        print('${now - lastTime}');
        lastTime = now;
        sink!.add(buffer.data!);
      }
    });

Thanks a lot, and I really appreciate all of the work that you're doing :D -B

PS: in the demo.dart, I do see a tBLOCKSIZE variable that could help (i.e. smaller blocks would induce faster updates), but this variable doesn't seem to be referenced anywhere...

mowgliho avatar Jan 03 '22 17:01 mowgliho

+1

lixp185 avatar Jun 16 '22 10:06 lixp185

I am having the same problem. It works great on my Samsung, but on iPhone it is laggy. Using sample rate 22050Hz and not writing to a file.

arnirichard avatar Oct 12 '22 23:10 arnirichard

There is some time from when recording is started in code until it actually starts, so the user must wait.

arnirichard avatar Oct 13 '22 14:10 arnirichard

Is the update frequency still slow for you @arnirichard ? I get updates only every 250ms or so on iPhones...

mowgliho avatar Nov 12 '22 05:11 mowgliho

@mowgliho I found the solution here: https://stackoverflow.com/questions/26115626/i-want-to-call-20-times-per-second-the-installtaponbusbuffersizeformatblock But this means you need to change the plugin code and since the owner of this package is inactive you will need to make a fork or something Also, I found that the optimal sample rate on iOS is 48000. Now it works much better.

arnirichard avatar Nov 12 '22 06:11 arnirichard

@mowgliho I just made a quick fix, combined flutter_sound and flutter_sound_core, and changed the relevant line of code, the result is here: https://www.arnirichard.dk/flutter_sound_2.zip Then I link into that code in pubspec.yaml: flutter_sound: path: ../flutter_sound_2/flutter_sound It is not optimal, maybe I will create new audio library from scratch one day

arnirichard avatar Nov 12 '22 06:11 arnirichard

Thanks for the solution! I'm having trouble testing it, unfortunately. I downloaded it to the path, changed the pubspec.yaml, and tried to build, but am now getting a lot of "Undefined symbol" errors (attached).

Would you perhaps have any sage advice? I thought perhaps it was some kind of caching issue, so I tried cleaning/rebuilding pods and flutter, checking out fresh copies from git, etc - but nothing seems to work... I'm a bit of an iOS development noob, I suppose.

In other news, in order to get it to run I had to change line 82 in FlautoRecorderEngine from inputStatus = AVAudioConverterInputStatus_HaveData ;5 to inputStatus = AVAudioConverterInputStatus_HaveData; I'm assuming that the "5" is a typo?

Thanks again!

Screen Shot 2022-11-12 at 9 05 05 AM

mowgliho avatar Nov 12 '22 15:11 mowgliho

@mowgliho Yes, sorry, I guess I added this 5 by accident. Hope it works now.

arnirichard avatar Nov 12 '22 19:11 arnirichard

I finally got it to work :D. I just had to add "-lc++" to the Other Linker Flags in Build Settings. Also had to remove flutter_sound_core as well as the two were combined.

Thanks!!!!

(from https://github.com/facebookarchive/pop/issues/25#issuecomment-41652577)

mowgliho avatar Nov 13 '22 04:11 mowgliho

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.

github-actions[bot] avatar Dec 06 '23 01:12 github-actions[bot]