Skip to content

Commit 9286260

Browse files
Fix delay when finalizing sound recording
1 parent da9f912 commit 9286260

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
0.5.2
22
=====
33
- AudioFlinger: optimize WAV volume scaling for speed and immediately set volume
4-
- AudioFlinger: eliminate thread by using TaskManager (asyncio)
4+
- AudioFlinger: add support for I2S microphone recording to WAV
55
- AppStore app: eliminate all thread by using TaskManager
66
- AppStore app: add support for BadgeHub backend
77
- OSUpdate app: show download speed

internal_filesystem/apps/com.micropythonos.soundrecorder/assets/sound_recorder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SoundRecorder(Activity):
3636

3737
# Constants
3838
MAX_DURATION_MS = 60000 # 60 seconds max recording
39-
RECORDINGS_DIR = "data/com.micropythonos.soundrecorder/recordings"
39+
RECORDINGS_DIR = "data/recordings"
4040

4141
# UI Widgets
4242
_status_label = None

internal_filesystem/lib/mpos/audio/stream_record.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,8 @@ def record(self):
261261

262262
print(f"RecordStream: max_bytes={max_bytes}, chunk_size={chunk_size}")
263263

264-
# Open file for appending audio data
265-
with open(self.file_path, 'r+b') as f:
266-
f.seek(44) # Skip header
267-
264+
# Open file for appending audio data (append mode to avoid seek issues)
265+
with open(self.file_path, 'ab') as f:
268266
buf = bytearray(chunk_size)
269267

270268
while self._keep_running and self._bytes_recorded < max_bytes:
@@ -294,8 +292,11 @@ def record(self):
294292
f.write(buf[:num_read])
295293
self._bytes_recorded += num_read
296294

297-
# Update header with actual data size
298-
print(f"RecordStream: Updating WAV header with data_size={self._bytes_recorded}")
295+
# Close the file first, then reopen to update header
296+
# This avoids the massive delay caused by seeking backwards in a large file
297+
# on ESP32 with SD card (FAT filesystem buffering issue)
298+
print(f"RecordStream: Updating WAV header with data_size={self._bytes_recorded}")
299+
with open(self.file_path, 'r+b') as f:
299300
self._update_wav_header(f, self._bytes_recorded)
300301

301302
elapsed_ms = time.ticks_diff(time.ticks_ms(), start_time)

0 commit comments

Comments
 (0)