RSHVR commited on
Commit
2210c38
·
verified ·
1 Parent(s): e562b67

Update tts.py

Browse files
Files changed (1) hide show
  1. tts.py +10 -4
tts.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
2
  import torch
3
  import torchaudio
4
- import spaces # Import spaces module for Zero-GPU
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
- @spaces.GPU # Add spaces.GPU decorator for Zero-GPU support
15
- async def generate_speech(text, voice_preset="random", voice_file_path=None):
 
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)