The method 'openAudioSession' isn't defined for the type 'FlutterSoundRecorder'

I am writing a flutter app for recording voice using flutter_sound package

environment:
  sdk: ">=2.15.1 <3.0.0"
dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  flutter_sound: ^9.1.2
  permission_handler: ^8.3.0
import 'package:flutter_sound/flutter_sound.dart';
import 'package:permission_handler/permission_handler.dart';
Future init() async {
    _audioRecorder = FlutterSoundRecorder();

    final status = await Permission.microphone.request();
    if (status != PermissionStatus.granted){
      throw RecordingPermissionException('Microphone permission denied.');
    }
    await _audioRecorder!.openAudioSession();
    _isRecorderInitiated = true;
 }

I am getting this error

The method 'openAudioSession' isn't defined for the type 'FlutterSoundRecorder'.

Can anybody help me in finding out what’s wrong with the code?

>Solution :

It seems to have been removed in version 9, but the documentation has not been updated. You can use openRecorder() instead or switch to an older version of the library.

Leave a Reply