From 73837730fa0f752d934ec266d7425de562974928 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sat, 4 Jan 2025 11:59:42 -0800 Subject: [PATCH] feat: Add file size check and mp3 conversion for large audio files --- aider/voice.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/aider/voice.py b/aider/voice.py index 5fb0433b2..e307c5f8e 100644 --- a/aider/voice.py +++ b/aider/voice.py @@ -140,10 +140,20 @@ class Voice: while not self.q.empty(): file.write(self.q.get()) - # ai: File uploads are currently limited to 25 MB - # check if the format is wav and the file is >25mb - # if so, offer to switch to mp3 format. ai! - if self.audio_format != "wav": + # Check file size and offer to convert to mp3 if too large + file_size = os.path.getsize(temp_wav) + if file_size > 25 * 1024 * 1024: # 25 MB + print("\nWarning: Recording is too large for direct upload (over 25MB)") + if input("Convert to mp3 to reduce size? [Y/n] ").lower() in ("", "y"): + filename = tempfile.mktemp(suffix=".mp3") + audio = AudioSegment.from_wav(temp_wav) + audio.export(filename, format="mp3") + os.remove(temp_wav) + print(f"Converted to mp3, new size: {os.path.getsize(filename)/1024/1024:.1f}MB") + else: + print("Uploading large file - may fail if over 25MB") + filename = temp_wav + elif self.audio_format != "wav": filename = tempfile.mktemp(suffix=f".{self.audio_format}") audio = AudioSegment.from_wav(temp_wav) audio.export(filename, format=self.audio_format)