mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
style: Format code to comply with linter rules
This commit is contained in:
parent
5cde755976
commit
9c4a0043dd
1 changed files with 38 additions and 23 deletions
|
@ -73,19 +73,22 @@ def compress_audio(input_file, output_file, bitrate=MP3_BITRATE):
|
||||||
if not check_ffmpeg():
|
if not check_ffmpeg():
|
||||||
print("Warning: FFmpeg not found, skipping compression")
|
print("Warning: FFmpeg not found, skipping compression")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
"-i", input_file,
|
"-i",
|
||||||
"-b:a", bitrate,
|
input_file,
|
||||||
"-ac", "1", # Mono audio
|
"-b:a",
|
||||||
|
bitrate,
|
||||||
|
"-ac",
|
||||||
|
"1", # Mono audio
|
||||||
"-y", # Overwrite output file
|
"-y", # Overwrite output file
|
||||||
output_file
|
output_file,
|
||||||
],
|
],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE
|
stderr=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
except subprocess.SubprocessError as e:
|
except subprocess.SubprocessError as e:
|
||||||
|
@ -111,13 +114,13 @@ def generate_audio_openai(text, output_file, voice=VOICE, bitrate=MP3_BITRATE):
|
||||||
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
|
||||||
temp_path = temp_file.name
|
temp_path = temp_file.name
|
||||||
temp_file.write(response.content)
|
temp_file.write(response.content)
|
||||||
|
|
||||||
# Get original file size
|
# Get original file size
|
||||||
original_size = os.path.getsize(temp_path)
|
original_size = os.path.getsize(temp_path)
|
||||||
|
|
||||||
# Compress the audio to reduce file size
|
# Compress the audio to reduce file size
|
||||||
success = compress_audio(temp_path, output_file, bitrate)
|
success = compress_audio(temp_path, output_file, bitrate)
|
||||||
|
|
||||||
# If compression failed or FFmpeg not available, use the original file
|
# If compression failed or FFmpeg not available, use the original file
|
||||||
if not success:
|
if not success:
|
||||||
with open(output_file, "wb") as f:
|
with open(output_file, "wb") as f:
|
||||||
|
@ -126,14 +129,17 @@ def generate_audio_openai(text, output_file, voice=VOICE, bitrate=MP3_BITRATE):
|
||||||
else:
|
else:
|
||||||
compressed_size = os.path.getsize(output_file)
|
compressed_size = os.path.getsize(output_file)
|
||||||
reduction = (1 - compressed_size / original_size) * 100
|
reduction = (1 - compressed_size / original_size) * 100
|
||||||
print(f" ℹ Compressed: {original_size} → {compressed_size} bytes ({reduction:.1f}% reduction)")
|
print(
|
||||||
|
f" ℹ Compressed: {original_size} → {compressed_size} bytes ({reduction:.1f}%"
|
||||||
|
" reduction)"
|
||||||
|
)
|
||||||
|
|
||||||
# Clean up the temporary file
|
# Clean up the temporary file
|
||||||
try:
|
try:
|
||||||
os.unlink(temp_path)
|
os.unlink(temp_path)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print(f"Error: {response.status_code}, {response.text}")
|
print(f"Error: {response.status_code}, {response.text}")
|
||||||
|
@ -186,10 +192,14 @@ def main():
|
||||||
"--force", action="store_true", help="Force regeneration of all audio files"
|
"--force", action="store_true", help="Force regeneration of all audio files"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--bitrate", default=MP3_BITRATE, help=f"MP3 bitrate for compression (default: {MP3_BITRATE})"
|
"--bitrate",
|
||||||
|
default=MP3_BITRATE,
|
||||||
|
help=f"MP3 bitrate for compression (default: {MP3_BITRATE})",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--compress-only", action="store_true", help="Only compress existing files without generating new ones"
|
"--compress-only",
|
||||||
|
action="store_true",
|
||||||
|
help="Only compress existing files without generating new ones",
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -211,7 +221,7 @@ def main():
|
||||||
print(f"Audio directory: {output_dir}")
|
print(f"Audio directory: {output_dir}")
|
||||||
if not args.dry_run:
|
if not args.dry_run:
|
||||||
os.makedirs(output_dir, exist_ok=True)
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
|
||||||
# If compress-only flag is set, just compress existing files
|
# If compress-only flag is set, just compress existing files
|
||||||
if args.compress_only:
|
if args.compress_only:
|
||||||
print("Compressing existing files only...")
|
print("Compressing existing files only...")
|
||||||
|
@ -219,11 +229,11 @@ def main():
|
||||||
for timestamp_key in metadata:
|
for timestamp_key in metadata:
|
||||||
filename = f"{timestamp_key}.mp3"
|
filename = f"{timestamp_key}.mp3"
|
||||||
file_path = os.path.join(output_dir, filename)
|
file_path = os.path.join(output_dir, filename)
|
||||||
|
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
temp_file = f"{file_path}.temp"
|
temp_file = f"{file_path}.temp"
|
||||||
print(f"Compressing: {filename}")
|
print(f"Compressing: {filename}")
|
||||||
|
|
||||||
if not args.dry_run:
|
if not args.dry_run:
|
||||||
success = compress_audio(file_path, temp_file, selected_bitrate)
|
success = compress_audio(file_path, temp_file, selected_bitrate)
|
||||||
if success:
|
if success:
|
||||||
|
@ -231,17 +241,20 @@ def main():
|
||||||
original_size = os.path.getsize(file_path)
|
original_size = os.path.getsize(file_path)
|
||||||
compressed_size = os.path.getsize(temp_file)
|
compressed_size = os.path.getsize(temp_file)
|
||||||
reduction = (1 - compressed_size / original_size) * 100
|
reduction = (1 - compressed_size / original_size) * 100
|
||||||
|
|
||||||
# Replace original with compressed version
|
# Replace original with compressed version
|
||||||
os.replace(temp_file, file_path)
|
os.replace(temp_file, file_path)
|
||||||
print(f" ✓ Compressed: {original_size} → {compressed_size} bytes ({reduction:.1f}% reduction)")
|
print(
|
||||||
|
f" ✓ Compressed: {original_size} → {compressed_size} bytes"
|
||||||
|
f" ({reduction:.1f}% reduction)"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print(f" ✗ Failed to compress")
|
print(f" ✗ Failed to compress")
|
||||||
if os.path.exists(temp_file):
|
if os.path.exists(temp_file):
|
||||||
os.remove(temp_file)
|
os.remove(temp_file)
|
||||||
else:
|
else:
|
||||||
print(f" Would compress: {file_path}")
|
print(f" Would compress: {file_path}")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Extract commentary markers
|
# Extract commentary markers
|
||||||
|
@ -302,7 +315,9 @@ def main():
|
||||||
print(f" Would generate: {output_file}")
|
print(f" Would generate: {output_file}")
|
||||||
else:
|
else:
|
||||||
print(f" Generating: {output_file}")
|
print(f" Generating: {output_file}")
|
||||||
success = generate_audio_openai(message, output_file, voice=selected_voice, bitrate=selected_bitrate)
|
success = generate_audio_openai(
|
||||||
|
message, output_file, voice=selected_voice, bitrate=selected_bitrate
|
||||||
|
)
|
||||||
if success:
|
if success:
|
||||||
print(f" ✓ Generated audio file")
|
print(f" ✓ Generated audio file")
|
||||||
# Update metadata with the new message
|
# Update metadata with the new message
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue