06153
06153

Reputation: 339

Changing audio playback speed

Is there any way to change (increase/decrease) audio playback speed using Flutter?

Couldn't find any info about it and it seems like writing native code is the only option.

Upvotes: 3

Views: 4135

Answers (4)

Amr Tawfik
Amr Tawfik

Reputation: 1

Try to use inappwebview package that will enable you to customize any Voice player using HTML Code by Sending it like that :

   initialUrlRequest: URLRequest(
          url: Uri.dataFromString(
              generateVoicePlayerHTML(voiceUrl),
              mimeType: 'text/html',
              encoding: Encoding.getByName('utf-8'))),

and you will create your Html Code inside abstract class "GenerateVoicePlayerHTML" also have many Attributes to use it depend on platform

References: https://pub.dev/packages/flutter_inappwebview

Upvotes: 0

Yuriy N.
Yuriy N.

Reputation: 6097

The more complete example of using audioplayers:

import 'dart:developer';
import 'package:audioplayers/audioplayers.dart';

class Player {
   static play(String src, Function onComplete, {double playbackRate = 1.0}) async {
    try {
      final player = AudioPlayer();
      await player.setPlaybackRate(playbackRate);
      await player.play(AssetSource(src));
      player.onPlayerComplete.listen((_) {
        onComplete();
      });
    } catch (e, stack) {
      log(src);
      log(e.toString());
      log(stack.toString());
    }
  }  


}

Use like:

Player.play(pathToFile, () {}); //normal speed
Player.play(pathToFile, () {}, playbackRate: 0.7); //slowly
Player.play(pathToFile, () {}, playbackRate: 1.5); //quickly

Note that setPlaybackRate has no effect on the Windows app. I did not try an emulator but on a real Android device and the web on Chrome works fine.

Upvotes: 1

syonip
syonip

Reputation: 2971

The package audioplayers has incorporated support for playback rate:

_audioPlayer.setPlaybackRate(playbackRate: 1.0);

Upvotes: 6

aleskva
aleskva

Reputation: 1805

Try an audioplayers_with_rate fork of audioplayers. It worked great for me, but I couldn't find where its code is located (it links to audioplayers). The same functionality provides this fork or this fork of audioplayers.

Upvotes: 0

Related Questions