mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 18:25:00 +00:00
refactor: Use temporary variable for audio format to avoid state mutation
This commit is contained in:
parent
de1d566e9e
commit
01ef2351b3
1 changed files with 7 additions and 5 deletions
|
@ -141,18 +141,20 @@ class Voice:
|
||||||
while not self.q.empty():
|
while not self.q.empty():
|
||||||
file.write(self.q.get())
|
file.write(self.q.get())
|
||||||
|
|
||||||
|
use_audio_format = self.audio_format
|
||||||
|
|
||||||
# Check file size and offer to convert to mp3 if too large
|
# Check file size and offer to convert to mp3 if too large
|
||||||
file_size = os.path.getsize(temp_wav)
|
file_size = os.path.getsize(temp_wav)
|
||||||
if file_size > 24.9 * 1024 * 1024 and self.audio_format == "wav":
|
if file_size > 24.9 * 1024 * 1024 and self.audio_format == "wav":
|
||||||
print("\nWarning: {temp_wav} is too large, switching to mp3 format.")
|
print("\nWarning: {temp_wav} is too large, switching to mp3 format.")
|
||||||
self.audio_format = "mp3"
|
use_audio_format = "mp3"
|
||||||
|
|
||||||
filename = temp_wav
|
filename = temp_wav
|
||||||
if self.audio_format != "wav":
|
if use_audio_format != "wav":
|
||||||
try:
|
try:
|
||||||
new_filename = tempfile.mktemp(suffix=f".{self.audio_format}")
|
new_filename = tempfile.mktemp(suffix=f".{use_audio_format}")
|
||||||
audio = AudioSegment.from_wav(temp_wav)
|
audio = AudioSegment.from_wav(temp_wav)
|
||||||
audio.export(filename, format=self.audio_format)
|
audio.export(filename, format=use_audio_format)
|
||||||
os.remove(temp_wav)
|
os.remove(temp_wav)
|
||||||
filename = new_filename
|
filename = new_filename
|
||||||
except (CouldntDecodeError, CouldntEncodeError) as e:
|
except (CouldntDecodeError, CouldntEncodeError) as e:
|
||||||
|
@ -171,7 +173,7 @@ class Voice:
|
||||||
print(f"Unable to transcribe {filename}: {err}")
|
print(f"Unable to transcribe {filename}: {err}")
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.audio_format != "wav":
|
if filename != temp_wav:
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
||||||
text = transcript.text
|
text = transcript.text
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue