How can I handle audio files?

120

Here is a package you can use audio_recorder

  • For record and storing part here is sample examples (read the package documentation)

     // Import package
     import 'package:audio_recorder/audio_recorder.dart';
    
     // Check permissions before starting
     bool hasPermissions = await AudioRecorder.hasPermissions;
    
     // Get the state of the recorder
     bool isRecording = await AudioRecorder.isRecording;
    
     // Start recording
     await AudioRecorder.start(path: _controller.text, audioOutputFormat: AudioOutputFormat.AAC);
    
     // Stop recording
     Recording recording = await AudioRecorder.stop();
     print("Path : ${recording.path},  Format : ${recording.audioOutputFormat},  Duration : ${recording.duration},  Extension : ${recording.extension},");
    
  • play audio you need another package i suggest audioplayers :

    // To pause 
    int result = await audioPlayer.pause();
    
    //To Stop 
    int result = await audioPlayer.stop();
    
    // To Jump through
    int result = await audioPlayer.seek(Duration(milliseconds: 1200));
    
    // To Resume 
    int result = await audioPlayer.resume(); 
    
Share:
120
Admin
Author by

Admin

Updated on December 23, 2022

Comments

  • Admin
    Admin over 1 year

    What is the best option to:

    1. Record audio from microphone,
    2. Store the audio as files in memory,
    3. Being able to play those files ?

    Is there one package that is convenient to record and play? Does it works on all platforms (web compatible)? What is the best strategy to store them in memory?