shukdevdatta123 commited on
Commit
f75668a
·
verified ·
1 Parent(s): 4760b00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # !pip install TTS gradio numpy librosa torch
2
 
3
  from TTS.api import TTS
4
  import gradio as gr
@@ -7,13 +7,14 @@ import librosa
7
  import torch
8
  import tempfile
9
  import os
 
10
 
11
  # Check device availability
12
  device = "cuda" if torch.cuda.is_available() else "cpu"
13
 
14
- # Initialize TTS model
15
  model_name = "tts_models/multilingual/multi-dataset/your_tts"
16
- tts = TTS(model_name=model_name).to(device)
17
 
18
  def process_audio(audio_path, max_duration=10):
19
  """Load and trim audio to specified duration"""
@@ -33,7 +34,7 @@ def generate_speech(audio_file, text):
33
 
34
  # Process reference audio
35
  y, sr = process_audio(audio_file)
36
- librosa.output.write_wav(ref_path, y, sr)
37
 
38
  # Generate speech
39
  try:
@@ -91,7 +92,7 @@ with gr.Blocks(title="Voice Clone TTS") as demo:
91
  inputs=[audio_input, text_input],
92
  outputs=audio_output,
93
  fn=generate_speech,
94
- cache_examples=True
95
  )
96
 
97
  btn.click(
 
1
+ # !pip install TTS gradio numpy librosa torch soundfile
2
 
3
  from TTS.api import TTS
4
  import gradio as gr
 
7
  import torch
8
  import tempfile
9
  import os
10
+ import soundfile as sf # Added for better audio handling
11
 
12
  # Check device availability
13
  device = "cuda" if torch.cuda.is_available() else "cpu"
14
 
15
+ # Initialize TTS model with device parameter
16
  model_name = "tts_models/multilingual/multi-dataset/your_tts"
17
+ tts = TTS(model_name=model_name).to(device) # This line is the problem
18
 
19
  def process_audio(audio_path, max_duration=10):
20
  """Load and trim audio to specified duration"""
 
34
 
35
  # Process reference audio
36
  y, sr = process_audio(audio_file)
37
+ sf.write(ref_path, y, sr) # Using soundfile instead of librosa for writing
38
 
39
  # Generate speech
40
  try:
 
92
  inputs=[audio_input, text_input],
93
  outputs=audio_output,
94
  fn=generate_speech,
95
+ cache_examples=False # Disabled cache to avoid potential issues
96
  )
97
 
98
  btn.click(