import gradio as gr import os import numpy as np from scipy.io.wavfile import write as write_wav # --- Configuration (same as before) --- # 1. List the names of your TTS models MODELS = ['sarvam', 'smallest', 'IndicVox', 'veena'] # 2. List the text prompts that correspond to your numbered audio files TEXTS = [ "संविधान की प्रस्तावना में निहित मूल्यों का परिपालन प्रत्येक नागरिक का कर्तव्य है।", "प्राकृतिक आपदाओं के निराकरण हेतु समुचित रणनीति आवश्यक है।", "उसके अभिव्यक्तिपरक लेखन में गूढ़ दर्शन और जीवन के गहन सत्य परिलक्षित होते हैं।", "किसी भी राष्ट्र की उन्नति उसके नागरिकों की कर्मठता पर निर्भर करती है।" ] # 3. Set the path to your audio directory AUDIO_DIR = "audio_files" # --- Helper Function to Create Dummy Audio (same as before) --- def create_dummy_files_if_needed(): """Checks for audio files and creates silent placeholders if they don't exist.""" print("Checking for audio files...") os.makedirs(AUDIO_DIR, exist_ok=True) files_created = False for model in MODELS: for i in range(len(TEXTS)): file_path = os.path.join(AUDIO_DIR, f"{model}-{i+1}.wav") if not os.path.exists(file_path): if not files_created: print(f"Warning: Audio file not found. Creating a dummy silent file at '{file_path}'.") print("Replace these dummy files with your actual audio samples.") files_created = True samplerate = 22050 data = np.zeros(samplerate * 1) # 1 second of silence write_wav(file_path, samplerate, data.astype(np.int16)) if not files_created: print("All audio files found successfully!") # --- Build the Gradio Interface (New and Improved) --- def build_app(): # First, ensure all audio files (or dummies) exist. create_dummy_files_if_needed() with gr.Blocks(theme=gr.themes.Soft(), title="TTS Comparison") as demo: gr.Markdown( """ # TTS Model Audio Comparison Listen to audio samples generated by different models for the same text. """ ) # --- Create the Header Row --- with gr.Row(): # Add an empty placeholder for the "Text Prompt" column header for alignment gr.Markdown("### Text Prompt") # Create a header for each model for model in MODELS: gr.Markdown(f"### {model.capitalize()}") # --- Create a Row for Each Text Prompt --- # Enumerate through the texts to get both an index (i) and the text content for i, text in enumerate(TEXTS): with gr.Row(variant="panel"): # Column 1: The text prompt gr.Textbox( value=text, label="Text Prompt", interactive=False, lines=3, show_label=False # The header row already provides context ) # Subsequent Columns: The audio players for each model for model in MODELS: # Construct the correct audio file path for this row and column audio_path = os.path.join(AUDIO_DIR, f"{model}-{i+1}.wav") gr.Audio( value=audio_path, label=model.capitalize(), # Label is good for accessibility show_label=False # Hide label for a cleaner look ) return demo if __name__ == "__main__": app = build_app() app.launch()