1

Decreasing the playback speed of AudioPlayer severely decreases the quality of the audio being played; the audio becomes very "noisy". Is there any way to fix this or is it an issue with the just_audio implementation?

Reproduce:

final AudioPlayer player = AudioPlayer(); // Create audio player
player.setAsset("..."); // Load audio file
player.setSpeed(0.5); // Halve speed
player.play(); // Start playing
BeMain
  • 11
  • 3

1 Answers1

0

Just to preface this answer, time stretching is a difficult thing to do in real-time because it has to stretch time without stretching the sound waves (stretching the sound waves would lower the frequency and hence the pitch, so it has to stretch time while filling the gaps with fabricated extensions to the existing sound waves). As a result, the very best real time algorithm will still introduce artifacts and distortions.

Now to answer your question, just_audio doesn't provide any options to change the time stretching algorithm, but it does use the best available algorithms for each platform, for general purpose usage. The Android implementation uses Sonic which is better quality than Android's own built-in algorithm. On iOS/macOS, AVAudioTimePitchAlgorithmTimeDomain is used which seems to produce the least distortion at speeds below 1.0 out of the different algorithms Apple provides, although newer iPhones/iOS versions may produce higher quality output. On web browsers, it uses whatever algorithm that web browser provides.

If you need to try out alternatives, you would need to make a copy of just_audio and edit the code that selects the algorithm. You are unlikely to find better options for Android and web, but you might like to experiment with the different iOS/macOS algorithms by searching for AVAudioTimePitchAlgorithmTimeDomain in the code and changing it to one of the other options listed in Apple's documentation. You may find one of the other algorithms works better if you have a specialised use case.

Ryan Heise
  • 2,273
  • 5
  • 14
  • Thank you for the detailed explanation! I'm aware of the difficulties in slowing down audio, but I've also worked with the package [pyrubberband](https://github.com/bmcfee/pyrubberband) before, and it barely decreases the quality at all. There are even mobile apps, like Amazing Slowdowner, that do a much better job at not decreasing the quality than just_audio does. I was hoping maybe there was some easy way to use another algorithm, or even implement my own. – BeMain Aug 15 '22 at 18:07
  • rubberband is GPL and therefore incompatible with the Apple and Google app stores. If you want to use rubberband, you need to pay them for a commercial licence from them, and then you would have to integrate it into the just_audio code yourself. – Ryan Heise Aug 16 '22 at 02:48
  • By the way, you didn't comment on a specific platform. – Ryan Heise Aug 16 '22 at 02:51
  • You're right, sorry. I'm primarily targeting Android, but iOS is also of some interest. – BeMain Aug 17 '22 at 08:45
  • That's unfortunate about rubberband, but perhaps there's some other algorithm I could implement...or perhaps I should just live with the quality just_audio offers :) – BeMain Aug 17 '22 at 09:00
  • There are some apps on the Play Store that have implemented audio looping without distorting the audio at low speeds. So, there must be some native library that can achieve distortion free audio looping at low speeds and that can be used to make a flutter plugin or integrated into just_audio – flutternoob Feb 04 '23 at 12:06