| import gradio as gr |
| import subprocess |
| import os |
| import tempfile |
| import imageio_ffmpeg |
|
|
| def convert_audio(input_files, progress=gr.Progress()): |
| if not input_files: |
| return [] |
|
|
| |
| ffmpeg_exe = imageio_ffmpeg.get_ffmpeg_exe() |
| |
| output_files = [] |
| |
| out_dir = tempfile.mkdtemp() |
|
|
| |
| for file_path in progress.tqdm(input_files, desc="Converting Audio..."): |
| filename = os.path.basename(file_path) |
| name_only = os.path.splitext(filename)[0] |
| |
| out_path = os.path.join(out_dir, f"{name_only}_96k_24b.m4a") |
|
|
| |
| command = [ |
| ffmpeg_exe, "-y", "-v", "error", |
| "-i", file_path, |
| "-c:a", "alac", |
| "-ar", "96000", |
| "-sample_fmt", "s32p", |
| out_path |
| ] |
|
|
| try: |
| |
| subprocess.run(command, check=True) |
| output_files.append(out_path) |
| except subprocess.CalledProcessError as e: |
| print(f"Error processing {filename}: {e}") |
| |
| return output_files |
|
|
| |
| with gr.Blocks(title="High-Res Audio Converter") as app: |
| gr.Markdown("# 🎵 Pure-Python High-Res FLAC to ALAC Converter") |
| gr.Markdown("Upload **384kHz / 24-bit FLAC** files. They will be converted to **96kHz / 24-bit ALAC (.m4a)** natively in your Python environment.") |
| |
| with gr.Row(): |
| audio_in = gr.File(label="1. Upload FLAC files", file_count="multiple", file_types=[".flac"], type="filepath") |
| audio_out = gr.File(label="2. Download Converted Files", file_count="multiple", interactive=False) |
| |
| convert_btn = gr.Button("Convert to ALAC (96kHz 24-bit)", variant="primary") |
| |
| convert_btn.click(fn=convert_audio, inputs=audio_in, outputs=audio_out) |
|
|
| if __name__ == "__main__": |
| app.launch() |