-
Notifications
You must be signed in to change notification settings - Fork 274
Description
Environment
- OS: Android 12
- Device: Poco X3 NFC
- Flutter SDK: 3.35.4
- Permissions: Microphone (granted)
- Encoders Tested: Opus, AAC LC, WAV
Describe the bug
After updating from record 5.2.0 to 6.1.2, the AudioRecorder produces 0-second recordings (corrupted files).
The encoder initializes successfully (AAC LC, Opus, and WAV all tested), but the resulting file contains only headers and no valid audio data.
The file size is around 6–8 KB and reports 0s duration when inspected or played back.
Record configuration used:
RecordConfig(encoder: AudioEncoder.opus)To Reproduce
-
Create a temporary file path:
final filePath = '${tempDir.path}/temp.${DateTime.now().millisecondsSinceEpoch}.opus';
-
Initialize and start the recorder:
final recorder = AudioRecorder(); await recorder.start( RecordConfig(encoder: AudioEncoder.opus), path: filePath, );
-
Wait a few seconds.
-
Stop the recorder:
await recorder.stop();
-
Attempt to play or inspect the recorded file.
- File size: ~6–8 KB
- Duration: 0s
- Appears corrupted
Expected behavior
The recorded file should contain valid audio data of the correct (non-zero) duration.
Additional context
Encoder logs show successful initialization:
D/CCodec (17780): allocate(c2.android.opus.encoder)
I/CCodecConfig(17780): query failed after returning 9 values (BAD_INDEX)
D/CCodecBufferChannel: [c2.android.opus.encoder#56] start: updating output delay 0
File path is correctly created:
/data/user/0/com.doctor.voice.patientDev/cache/temp.1760713610632.opus
Playback logs show:
! Audio duration is too small 0s — possibly corrupted
Simplified code example:
abstract class BaseRecordingCubit extends Cubit<BaseRecordingState> {
final AudioRecorder recorder = AudioRecorder();
String? filePath;
Future<void> startRecording() async {
if (await recorder.hasPermission()) {
filePath =
'${(await getTemporaryDirectory()).path}/temp.${DateTime.now().millisecondsSinceEpoch}.opus';
await recorder.start(
RecordConfig(encoder: AudioEncoder.opus),
path: filePath!,
);
}
}
Future<void> stopRecording() async {
if (await recorder.isRecording()) {
await recorder.stop();
}
}
}Logs:
V/MediaPlayer(21075): resetDrmState: mDrmInfo=null ...
D/AudioRecord(21075): set(): inputSource 0, sampleRate 44100, ...
D/AudioManager(21075): dispatching onAudioFocusChange(-1) ...
Workaround:
Downgrading to version 5.2.1 fixes the issue.
Version 6.1.2 consistently produces corrupted (0s) audio files.