Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,25 @@ import gradio as gr
|
|
| 2 |
import subprocess
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Define paths to the TTS model and vocoder files
|
| 6 |
MODEL_PATH = "models/v1/hi/fastpitch/best_model.pth"
|
| 7 |
CONFIG_PATH = "models/v1/hi/fastpitch/config.json"
|
| 8 |
VOCODER_PATH = "models/v1/hi/hifigan/best_model.pth"
|
| 9 |
VOCODER_CONFIG_PATH = "models/v1/hi/hifigan/config.json"
|
| 10 |
OUTPUT_FILE = "output.mp4"
|
|
|
|
| 11 |
|
| 12 |
def generate_speech(text: str) -> str:
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
Returns the path to the output audio file.
|
| 16 |
"""
|
|
|
|
|
|
|
| 17 |
try:
|
|
|
|
|
|
|
|
|
|
| 18 |
# Construct the command for speech synthesis
|
| 19 |
command = [
|
| 20 |
"python3", "-m", "TTS.bin.synthesize",
|
|
@@ -26,7 +32,7 @@ def generate_speech(text: str) -> str:
|
|
| 26 |
"--speaker_idx", "female",
|
| 27 |
"--out_path", OUTPUT_FILE
|
| 28 |
]
|
| 29 |
-
|
| 30 |
# Run the command
|
| 31 |
result = subprocess.run(command, capture_output=True, text=True)
|
| 32 |
|
|
@@ -34,12 +40,16 @@ def generate_speech(text: str) -> str:
|
|
| 34 |
if result.returncode != 0:
|
| 35 |
raise Exception(f"Error: {result.stderr}")
|
| 36 |
|
| 37 |
-
# Return the path to the generated output file
|
| 38 |
-
return OUTPUT_FILE
|
| 39 |
|
| 40 |
except Exception as e:
|
| 41 |
return str(e)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
# Create the Gradio interface
|
| 44 |
interface = gr.Interface(
|
| 45 |
fn=generate_speech,
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Define paths to the TTS model and vocoder files (relative to the Indic-TTS folder)
|
| 6 |
MODEL_PATH = "models/v1/hi/fastpitch/best_model.pth"
|
| 7 |
CONFIG_PATH = "models/v1/hi/fastpitch/config.json"
|
| 8 |
VOCODER_PATH = "models/v1/hi/hifigan/best_model.pth"
|
| 9 |
VOCODER_CONFIG_PATH = "models/v1/hi/hifigan/config.json"
|
| 10 |
OUTPUT_FILE = "output.mp4"
|
| 11 |
+
INDIC_TTS_FOLDER = "Indic-TTS" # Folder where the TTS system is located
|
| 12 |
|
| 13 |
def generate_speech(text: str) -> str:
|
| 14 |
"""
|
| 15 |
+
Navigate to the Indic-TTS folder, run the TTS synthesis command, and return to the original directory.
|
| 16 |
+
Returns the path to the output audio file or an error message.
|
| 17 |
"""
|
| 18 |
+
original_dir = os.getcwd() # Save the current working directory
|
| 19 |
+
|
| 20 |
try:
|
| 21 |
+
# Change to the Indic-TTS directory
|
| 22 |
+
os.chdir(INDIC_TTS_FOLDER)
|
| 23 |
+
|
| 24 |
# Construct the command for speech synthesis
|
| 25 |
command = [
|
| 26 |
"python3", "-m", "TTS.bin.synthesize",
|
|
|
|
| 32 |
"--speaker_idx", "female",
|
| 33 |
"--out_path", OUTPUT_FILE
|
| 34 |
]
|
| 35 |
+
|
| 36 |
# Run the command
|
| 37 |
result = subprocess.run(command, capture_output=True, text=True)
|
| 38 |
|
|
|
|
| 40 |
if result.returncode != 0:
|
| 41 |
raise Exception(f"Error: {result.stderr}")
|
| 42 |
|
| 43 |
+
# Return the full path to the generated output file
|
| 44 |
+
return os.path.join(os.getcwd(), OUTPUT_FILE)
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
return str(e)
|
| 48 |
|
| 49 |
+
finally:
|
| 50 |
+
# Change back to the original directory
|
| 51 |
+
os.chdir(original_dir)
|
| 52 |
+
|
| 53 |
# Create the Gradio interface
|
| 54 |
interface = gr.Interface(
|
| 55 |
fn=generate_speech,
|