Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from
|
4 |
-
import
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
model_path = "best_model.pth" # Directory where
|
8 |
-
config_path = "config.json"
|
9 |
|
10 |
-
#
|
11 |
-
|
|
|
12 |
|
13 |
def generate_speech(text):
|
14 |
# Generate speech using the model
|
15 |
-
|
16 |
-
|
17 |
-
#
|
|
|
|
|
|
|
|
|
18 |
with open(audio_path, "rb") as f:
|
19 |
audio_data = f.read()
|
20 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from TTS.utils.generic_utils import download_model
|
3 |
+
from TTS.utils.io import load_config
|
4 |
+
from TTS import TTS
|
5 |
+
import numpy as np
|
6 |
+
import soundfile as sf
|
7 |
|
8 |
+
# Define paths to the model and configuration
|
9 |
+
model_path = "best_model.pth" # Directory where your model is saved
|
10 |
+
config_path = "config.json" # Configuration file
|
11 |
|
12 |
+
# Load the model
|
13 |
+
config = load_config(config_path)
|
14 |
+
tts = TTS(config, model_path=model_path)
|
15 |
|
16 |
def generate_speech(text):
|
17 |
# Generate speech using the model
|
18 |
+
wav = tts.synthesize(text)
|
19 |
+
|
20 |
+
# Save the generated audio to a temporary file
|
21 |
+
audio_path = "output.wav"
|
22 |
+
sf.write(audio_path, wav, tts.sampling_rate)
|
23 |
+
|
24 |
+
# Read the audio file to return as binary data
|
25 |
with open(audio_path, "rb") as f:
|
26 |
audio_data = f.read()
|
27 |
|