PuristanLabs1 commited on
Commit
b128216
·
verified ·
1 Parent(s): a0dfdc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -108,11 +108,12 @@ def detect_language(text):
108
  def generate_audio_kokoro(text, lang):
109
  """Generate speech using KokoroTTS for supported languages."""
110
  global kokoro_tts # Access the preloaded model
111
- kokoro_tts.device = "cuda"
 
112
  lang_code = SUPPORTED_TTS_LANGUAGES.get(lang, "a") # Default to English
113
  generator = kokoro_tts(text, voice="af_bella", speed=1, split_pattern=r'\n+')
114
  # 3. Specify Device
115
- device = 'cuda' if torch.cuda.is_available() else 'cpu'
116
 
117
  # Initialize an empty list to store audio data
118
  audio_data_list = []
@@ -125,7 +126,8 @@ def generate_audio_kokoro(text, lang):
125
  # Concatenate all audio data into a single array
126
  full_audio = np.concatenate(audio_data_list)
127
  # Move model back to CPU after processing
128
- kokoro_tts.device = "cpu"
 
129
 
130
  output_file = f"audio_{lang}.wav"
131
  sf.write(output_file, full, 24000) # Save as WAV file
 
108
  def generate_audio_kokoro(text, lang):
109
  """Generate speech using KokoroTTS for supported languages."""
110
  global kokoro_tts # Access the preloaded model
111
+ kokoro_tts.to("cuda")
112
+
113
  lang_code = SUPPORTED_TTS_LANGUAGES.get(lang, "a") # Default to English
114
  generator = kokoro_tts(text, voice="af_bella", speed=1, split_pattern=r'\n+')
115
  # 3. Specify Device
116
+ #device = 'cuda' if torch.cuda.is_available() else 'cpu'
117
 
118
  # Initialize an empty list to store audio data
119
  audio_data_list = []
 
126
  # Concatenate all audio data into a single array
127
  full_audio = np.concatenate(audio_data_list)
128
  # Move model back to CPU after processing
129
+ #kokoro_tts.device = "cpu"
130
+ #model.to("cpu")
131
 
132
  output_file = f"audio_{lang}.wav"
133
  sf.write(output_file, full, 24000) # Save as WAV file