""" WaveWash Hugging Face Space App Author: Boobalan Arjunan """ import tempfile import pathlib import gradio as gr try: import spaces HAVE_SPACES = True except ImportError: HAVE_SPACES = False from wavewash.config import PROFILES from wavewash.quality_checker import analyze_file, load_audio from wavewash.audio_fixer import apply_fix_pipeline, save_audio def _process_audio_impl(audio_path, purpose): if not audio_path: return None, "Please upload or record an audio file." profile = PROFILES.get(purpose, PROFILES["asr"]) path = pathlib.Path(audio_path) # 1. Inspect original audio report = analyze_file(path, profile) # Build metric summary markdown status_emoji = "✅ Passed" if not report.issues else "⚠️ Issues Detected" metrics_table = f""" ### 📊 Audio Quality Inspection Report **Overall Status:** {status_emoji} **Selected Target Profile:** `{profile.name}` | Measurement | Value | Target / Threshold | | :--- | :--- | :--- | | **Duration** | {report.duration_sec:.2f} s | {profile.min_duration_sec}s – {profile.max_duration_sec}s | | **Sample Rate** | {report.sample_rate} Hz | Target: {profile.target_sample_rate} Hz | | **Channels** | {'Mono' if report.channels == 1 else 'Stereo'} | Target: {'Mono' if profile.target_channels == 1 else 'Stereo'} | | **SNR (Est.)** | {f"{report.snr_db:.1f} dB" if report.snr_db is not None else "N/A"} | Min: {profile.min_snr_db} dB | | **Clipped Ratio** | {f"{report.clipped_ratio * 100:.3f}%" if report.clipped_ratio is not None else "0.0%"} | Max: {profile.max_clipped_ratio * 100:.3f}% | | **DC Offset** | {f"{report.dc_offset:.4f}" if report.dc_offset is not None else "0.0"} | Max: {profile.max_dc_offset} | | **Loudness** | {f"{report.lufs:.1f} LUFS" if report.lufs is not None else "N/A"} | Target: {profile.target_lufs:.1f} LUFS | | **Silence Ratio** | {f"{report.silence_ratio * 100:.1f}%" if report.silence_ratio is not None else "N/A"} | Max: {profile.max_silence_ratio * 100:.1f}% | """ if report.issues: issues_text = "### 🚩 Detected Issues\n" + "\n".join([f"- `{i}`" for i in report.issues]) else: issues_text = "### ✨ No Critical Issues Found (Clean audio)" # 2. Apply automated repairs audio, sr, _ = load_audio(path) fixed_audio, fixed_sr, applied = apply_fix_pipeline(audio, sr, profile, report.issues) # Save repaired audio temp_dir = pathlib.Path(tempfile.mkdtemp()) out_file = temp_dir / f"repaired_{path.name}" save_audio(fixed_audio, fixed_sr, out_file, bit_depth=profile.target_bit_depth) # Re-verify repaired audio post_report = analyze_file(out_file, profile) if applied: fixes_text = "### 🛠️ Automated Fixes Applied\n" + "\n".join([f"- {f}" for f in applied]) else: fixes_text = "### 🛠️ No Fixes Needed (Audio is already compliant)" post_status = "✅ Clean & ML-Ready" if not post_report.issues else "⚠️ Remaining Warnings: " + ", ".join(post_report.issues) fixes_text += f"\n\n**Post-Repair Verification:** `{post_status}`" full_report = f"{metrics_table}\n\n{issues_text}\n\n{fixes_text}" return str(out_file), full_report if HAVE_SPACES: process_audio = spaces.GPU(_process_audio_impl) else: process_audio = _process_audio_impl with gr.Blocks(title="WaveWash — Audio QC & Data Prep", theme=gr.themes.Soft()) as demo: gr.Markdown(""" # 🌊 WaveWash: Audio QC & Data Prep for Speech ML **Created by [Boobalan Arjunan](https://github.com/BoobalanArjunan)** *Check, repair, and normalize audio datasets for ASR (Whisper), TTS, Voice AI, and Music Generation.* [![PyPI](https://img.shields.io/pypi/v/wavewash.svg)](https://pypi.org/project/wavewash/) [![GitHub](https://img.shields.io/badge/GitHub-BoobalanArjunan%2Fwavewash-blue)](https://github.com/BoobalanArjunan/wavewash) """) with gr.Row(): with gr.Column(scale=1): input_audio = gr.Audio(label="Upload or Record Audio", type="filepath") purpose_select = gr.Dropdown( label="Target ML Purpose", choices=[ ("ASR (Speech Recognition / Whisper)", "asr"), ("TTS (Voice Synthesis / Single-Speaker)", "tts"), ("Speaker Recognition / Diarization", "speaker_id"), ("Music Generation / Audio Fidelity", "music_gen"), ], value="asr" ) submit_btn = gr.Button("⚡ Analyze & Repair Audio", variant="primary") with gr.Column(scale=1): repaired_audio = gr.Audio(label="Repaired & Normalized Audio Output", type="filepath") report_output = gr.Markdown(label="Audit Report") submit_btn.click( fn=process_audio, inputs=[input_audio, purpose_select], outputs=[repaired_audio, report_output], api_name=False ) gr.Markdown(""" --- ### 💻 Local Desktop / Batch Processing Need to process 50,000+ files locally on your machine with a zero-config Web UI? ```bash pip install wavewash wavewash app ``` """) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)