mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
feat: add error handling and feedback for audio conversion
This commit is contained in:
parent
f9408640a3
commit
1851de323d
1 changed files with 16 additions and 4 deletions
|
@ -18,6 +18,7 @@ warnings.filterwarnings("ignore", category=SyntaxWarning)
|
||||||
|
|
||||||
|
|
||||||
from pydub import AudioSegment # noqa
|
from pydub import AudioSegment # noqa
|
||||||
|
from pydub.exceptions import CouldntDecodeError, CouldntEncodeError # noqa
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
|
@ -147,10 +148,21 @@ class Voice:
|
||||||
self.audio_format = "mp3"
|
self.audio_format = "mp3"
|
||||||
|
|
||||||
if self.audio_format != "wav":
|
if self.audio_format != "wav":
|
||||||
filename = tempfile.mktemp(suffix=f".{self.audio_format}")
|
try:
|
||||||
audio = AudioSegment.from_wav(temp_wav)
|
filename = tempfile.mktemp(suffix=f".{self.audio_format}")
|
||||||
audio.export(filename, format=self.audio_format)
|
audio = AudioSegment.from_wav(temp_wav)
|
||||||
os.remove(temp_wav)
|
audio.export(filename, format=self.audio_format)
|
||||||
|
os.remove(temp_wav)
|
||||||
|
print(f"Converted to {self.audio_format}, new size: {os.path.getsize(filename)/1024/1024:.1f}MB")
|
||||||
|
except (CouldntDecodeError, CouldntEncodeError) as e:
|
||||||
|
print(f"Error converting audio: {e}")
|
||||||
|
filename = temp_wav # fall back to original file
|
||||||
|
except (OSError, FileNotFoundError) as e:
|
||||||
|
print(f"File system error during conversion: {e}")
|
||||||
|
filename = temp_wav # fall back to original file
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Unexpected error during audio conversion: {e}")
|
||||||
|
filename = temp_wav # fall back to original file
|
||||||
else:
|
else:
|
||||||
filename = temp_wav
|
filename = temp_wav
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue