You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if a single Opus frame is corrupted during decoding, the entire recording fails. This is too aggressive and can result in complete data loss.
Uint8List_processOpus() {
final decodedSamples =<int>[];
for (final frame in frames) {
final decoded = _opusDecoder!.decode(input:Uint8List.fromList(frame));
decodedSamples.addAll(decoded); // Fails entire decode if one frame bad
}
return_convertToLittleEndianBytes(decodedSamples);
}
Suggested Solution
Skip corrupted frames instead of failing:
Uint8List_processOpus() {
final decodedSamples =<int>[];
int skippedFrames =0;
for (int i =0; i < frames.length; i++) {
try {
final decoded = _opusDecoder!.decode(input:Uint8List.fromList(frames[i]));
decodedSamples.addAll(decoded);
} catch (e) {
debugPrint('[WavBytesUtil] Skipping corrupted Opus frame $i: $e');
skippedFrames++;
// Insert silence for corrupted frame (20ms at 16kHz = 320 samples)
decodedSamples.addAll(List.filled(320, 0));
}
}
if (skippedFrames >0) {
debugPrint('[WavBytesUtil] Skipped $skippedFrames corrupted frames');
}
return_convertToLittleEndianBytes(decodedSamples);
}
Benefits
Partial recording recovery instead of complete failure
Better user experience (some audio > no audio)
More resilient to BLE transmission errors
Graceful degradation
Trade-offs
Introduces brief silence/gaps in audio where frames were corrupted
Could mask data quality issues if not logged properly
Problem
Currently, if a single Opus frame is corrupted during decoding, the entire recording fails. This is too aggressive and can result in complete data loss.
Location:
lib/utils/audio/wav_bytes_util.dart:176-185Suggested Solution
Skip corrupted frames instead of failing:
Benefits
Trade-offs
Priority
Medium - Improves robustness for edge cases
Related