Spaces:
Build error
Build error
Update tts.py
Browse files
tts.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import torch
|
3 |
import torchaudio
|
4 |
-
import spaces
|
5 |
from tortoise.api import TextToSpeech
|
6 |
from tortoise.utils.audio import load_audio
|
7 |
|
@@ -11,8 +11,9 @@ os.makedirs("outputs", exist_ok=True)
|
|
11 |
# Create a global TTS model instance
|
12 |
tts_model = None
|
13 |
|
14 |
-
|
15 |
-
|
|
|
16 |
global tts_model
|
17 |
|
18 |
try:
|
@@ -49,4 +50,9 @@ async def generate_speech(text, voice_preset="random", voice_file_path=None):
|
|
49 |
|
50 |
except Exception as e:
|
51 |
print(f"Error generating speech: {str(e)}")
|
52 |
-
raise
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import torch
|
3 |
import torchaudio
|
4 |
+
import spaces
|
5 |
from tortoise.api import TextToSpeech
|
6 |
from tortoise.utils.audio import load_audio
|
7 |
|
|
|
11 |
# Create a global TTS model instance
|
12 |
tts_model = None
|
13 |
|
14 |
+
# Synchronous function with GPU decorator
|
15 |
+
@spaces.GPU
|
16 |
+
def _generate_speech_gpu(text, voice_preset="random", voice_file_path=None):
|
17 |
global tts_model
|
18 |
|
19 |
try:
|
|
|
50 |
|
51 |
except Exception as e:
|
52 |
print(f"Error generating speech: {str(e)}")
|
53 |
+
raise
|
54 |
+
|
55 |
+
# Async wrapper that calls the GPU function
|
56 |
+
async def generate_speech(text, voice_preset="random", voice_file_path=None):
|
57 |
+
# Call the GPU-decorated function
|
58 |
+
return _generate_speech_gpu(text, voice_preset, voice_file_path)
|