[HELP] iOS Stream recording update frequency
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...
+1
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.
There is some time from when recording is started in code until it actually starts, so the user must wait.
Is the update frequency still slow for you @arnirichard ? I get updates only every 250ms or so on iPhones...
@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.
@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
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!

@mowgliho Yes, sorry, I guess I added this 5 by accident. Hope it works now.
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)
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.