Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,7 @@ from pydub import AudioSegment
|
|
13 |
from dotenv import load_dotenv
|
14 |
import tempfile
|
15 |
import spaces
|
|
|
16 |
|
17 |
# Load environment variables
|
18 |
load_dotenv()
|
@@ -55,18 +56,15 @@ def generate_script(user_prompt: str, model_id: str, token: str, duration: int):
|
|
55 |
# Voice-Over Generation Function
|
56 |
# ---------------------------------------------------------------------
|
57 |
@spaces.GPU(duration=300)
|
58 |
-
def generate_voice(script: str, speaker: str):
|
59 |
try:
|
60 |
-
#
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
inputs = processor(script, return_tensors="pt")
|
66 |
-
speech = model.generate(**inputs)
|
67 |
-
|
68 |
output_path = f"{tempfile.gettempdir()}/generated_voice.wav"
|
69 |
-
|
|
|
70 |
return output_path
|
71 |
except Exception as e:
|
72 |
return f"Error generating voice-over: {e}"
|
|
|
13 |
from dotenv import load_dotenv
|
14 |
import tempfile
|
15 |
import spaces
|
16 |
+
from TTS.api import TTS
|
17 |
|
18 |
# Load environment variables
|
19 |
load_dotenv()
|
|
|
56 |
# Voice-Over Generation Function
|
57 |
# ---------------------------------------------------------------------
|
58 |
@spaces.GPU(duration=300)
|
59 |
+
def generate_voice(script: str, speaker: str = "default"):
|
60 |
try:
|
61 |
+
# Load the TTS model
|
62 |
+
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", gpu=torch.cuda.is_available())
|
63 |
+
|
64 |
+
# Generate the speech audio file
|
|
|
|
|
|
|
|
|
65 |
output_path = f"{tempfile.gettempdir()}/generated_voice.wav"
|
66 |
+
tts.tts_to_file(text=script, file_path=output_path, speaker=speaker)
|
67 |
+
|
68 |
return output_path
|
69 |
except Exception as e:
|
70 |
return f"Error generating voice-over: {e}"
|