|
import gradio as gr |
|
import subprocess |
|
import os |
|
|
|
|
|
MODEL_PATH = "models/v1/hi/fastpitch/best_model.pth" |
|
CONFIG_PATH = "models/v1/hi/fastpitch/config.json" |
|
VOCODER_PATH = "models/v1/hi/hifigan/best_model.pth" |
|
VOCODER_CONFIG_PATH = "models/v1/hi/hifigan/config.json" |
|
OUTPUT_FILE = "output.mp4" |
|
INDIC_TTS_FOLDER = "Indic-TTS" |
|
|
|
def generate_speech(text: str) -> str: |
|
""" |
|
Navigate to the Indic-TTS folder, run the TTS synthesis command, and return to the original directory. |
|
Returns the path to the output audio file or an error message. |
|
""" |
|
original_dir = os.getcwd() |
|
|
|
try: |
|
|
|
os.chdir(INDIC_TTS_FOLDER) |
|
|
|
|
|
command = [ |
|
"python3", "-m", "TTS.bin.synthesize", |
|
"--text", text, |
|
"--model_path", MODEL_PATH, |
|
"--config_path", CONFIG_PATH, |
|
"--vocoder_path", VOCODER_PATH, |
|
"--vocoder_config_path", VOCODER_CONFIG_PATH, |
|
"--speaker_idx", "female", |
|
"--out_path", OUTPUT_FILE |
|
] |
|
|
|
|
|
result = subprocess.run(command, capture_output=True, text=True) |
|
|
|
|
|
if result.returncode != 0: |
|
raise Exception(f"Error: {result.stderr}") |
|
|
|
|
|
return os.path.join(os.getcwd(), OUTPUT_FILE) |
|
|
|
except Exception as e: |
|
return str(e) |
|
|
|
finally: |
|
|
|
os.chdir(original_dir) |
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_speech, |
|
inputs=gr.Textbox(label="Enter Text", placeholder="Type some text to synthesize..."), |
|
outputs=gr.File(label="Download Speech"), |
|
title="Hindi Speech Synthesis", |
|
description="Enter text in Hindi and generate speech using the FastPitch TTS model." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|