Open BubuKunz opened 4 months ago
Yes, this problem is known. There is a long string of processes working for delivering audio stream. Every body does buffering so they don’t lose audio packets and be sure to give packets in time to the lower process.
This is not easy to control all these buffers. The last buffers are managed by the os and we don’t have control on them.
‘But on iOS we have a layer managing several buffers (5?) just above the os. Very recently I implemented a callback "when finished " which is fired when those (5?) buffers are consumed by the os. This feature has been implemented and tested for app feeding the sink stream without waiting for a back pressure. I am not sure that it will do something useful for app waiting for each future completed (as you do if I understand correctly). You can try and tell us if this solves your problem.
‘If not, I will try to find with you another solution. Be sure to use the last version of flutter sound.
Also, if after waiting for the (5?) buffers consumed you still have truncation of the last buffers, you can try to lower the buffer size. But be careful: if too low, you may have some audio packets lost. Also, this can increase the cpu load a little bit.
player.strartPlayer( …. whenFinished: (){ do something;} … );
Flutter Sound Version :
FULL
Important: Result of the command :
flutter pub deps | grep flutter_sound
├── flutter_sound 9.4.15 │ ├── flutter_sound_platform_interface 9.4.15 │ ├── flutter_sound_web 9.4.15 │ │ ├── flutter_sound_platform_interface...
Severity
Platforms you faced the error
iOS - Yes (simulator)
Android ?
Flutter Web ?
Emulator ?
Real device ?
Describe the bug I'm working with elevenlabs TTS API. I want to have
To Reproduce Steps to reproduce the behavior:
Actual result: without 500ms delay it trims audio (kind of next line after 'await player.feedFromStream()' is reachebale before audio exactly finished)
` final List<Future> _audioPartsQueue = [];
Future _playFlutterSoundStream(
VoidCallback onStartPlaying,
) async {
await _myPlayer.startPlayerFromStream(
codec: flutter_sound.Codec.pcm16,
numChannels: 1,
sampleRate: 22050,
);
var startedPlaying = false;
while (_audioPartsQueue.isNotEmpty) {
final bytes = await _audioPartsQueue.removeAt(0);
if (!startedPlaying) {
onStartPlaying();
startedPlaying = true;
}
await _myPlayer.feedFromStream(bytes);
if (_audioPartsQueue.isEmpty) {
// need to add delay because the end of audio is trimmed if stop player without delay
await Future.delayed(const Duration(milliseconds: 500));
}
}
await _myPlayer.stopPlayer();
}
}`