llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
232 stars 193 forks source link

When recording to a stream calling stop crashes on Android #325

Closed bayasdev closed 3 months ago

bayasdev commented 4 months ago

Package version record 5.1.0 and record_android 1.2.1

Environment

Describe the bug

When recording audio to a stream calling stop crashes the app only on Android

I/flutter (21998): AudioRecorderService: Voice detected: false
I/flutter (21998): AudioRecorderService: Stopping recording
E/AndroidRuntime(21998): FATAL EXCEPTION: Thread-7
E/AndroidRuntime(21998): Process: com.example, PID: 21998
E/AndroidRuntime(21998): java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime(21998):    at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:431)
E/AndroidRuntime(21998):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:272)
2
E/AndroidRuntime(21998):    at com.llfbandit.record.methodcall.RecorderWrapper$stop$1.invoke(RecorderWrapper.kt:113)
E/AndroidRuntime(21998):    at com.llfbandit.record.record.recorder.AudioRecorder.onStop(AudioRecorder.kt:122)
E/AndroidRuntime(21998):    at com.llfbandit.record.record.recorder.RecordThread.updateState(RecordThread.kt:162)
E/AndroidRuntime(21998):    at com.llfbandit.record.record.recorder.RecordThread.onEncoderStop(RecordThread.kt:65)
E/AndroidRuntime(21998):    at com.llfbandit.record.record.encoder.PassthroughEncoder$EncodeThread.encode(PassthroughEncoder.kt:106)
E/AndroidRuntime(21998):    at com.llfbandit.record.record.encoder.PassthroughEncoder$EncodeThread.run(PassthroughEncoder.kt:69)
I/Process (21998): Sending signal. PID: 21998 SIG: 9
Lost connection to device.

Add your record configuration RecordConfig(...)

const RecordConfig(
    encoder: AudioEncoder.pcm16bits,
    sampleRate: 16000,
    numChannels: 1,
  );

To Reproduce

Call recorder like this

final recorderStream = await _recorder.startStream(_recorderConfig);

When I stop the recorder (eg: VAD silent signal) like this

await _recorder.stop();

It crashes only on Android, iOS is working fine

Expected behavior

It should not crash on Android

Additional context

Add any other context about the problem here.

llfbandit commented 4 months ago

I can't reproduce it with the example project. Can you provide a reproducer?

llfbandit commented 4 months ago

Version 5.1.1 has been released. It may worth a try. Feedback welcomed!

Roee-Tsur commented 2 months ago

Didn't try upgrading the package but for me this happens when stop was called twice and together.

bhargav-me commented 2 months ago

@llfbandit - This issue is reproducible on Android devices with v5.1.1

It can be reproduced by calling start and stop in quick succession [recordings of 1s]. It generally crashes while stopping the 3rd or 4th recording.