Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -15,13 +15,23 @@ with patch('builtins.input', always_yes):
15
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
16
  tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", progress_bar=False).to(device)
17
 
 
18
  def generate_voice(text, audio_file_path):
19
- output_path = "/content/cloned_audio.wav" # Setting the output path
20
- tts.tts_to_file(text,
21
- speaker_wav=audio_file_path, # Directly use the file path string
22
- language="en", # Assuming the language is English
23
- file_path=output_path,
24
- split_sentences=True)
 
 
 
 
 
 
 
 
 
25
  return output_path
26
 
27
  import gradio as gr
 
15
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
16
  tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", progress_bar=False).to(device)
17
 
18
+
19
  def generate_voice(text, audio_file_path):
20
+ # Create a directory if it does not exist
21
+ output_dir = "/tmp/"
22
+ if not os.path.exists(output_dir):
23
+ os.makedirs(output_dir)
24
+
25
+ output_path = os.path.join(output_dir, "cloned_audio.wav") # Using /tmp/ directory
26
+ tts.tts_to_file(
27
+ text,
28
+ speaker_wav=audio_file_path, # Directly use the file path string
29
+ language="en", # Assuming the language is English
30
+ file_path=output_path,
31
+ split_sentences=True,
32
+ # Assuming the TTS model requires a speaker identifier and '1' is a valid identifier
33
+ speaker="1"
34
+ )
35
  return output_path
36
 
37
  import gradio as gr