Hematej commited on
Commit
300bc4b
Β·
verified Β·
1 Parent(s): 804826d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -30,6 +30,9 @@ de_tts.to(device)
30
  es_tts.to(device)
31
 
32
  def text_to_speech(text: str, speaker_wav: str, speaker_wav_file: str) -> str:
 
 
 
33
  if not text:
34
  return "Error: No text provided."
35
 
@@ -40,7 +43,7 @@ def change_aud(text: str, speaker_wav: str, speaker_wav_file: str) -> str:
40
  if speaker_wav_file and not speaker_wav:
41
  speaker_wav = speaker_wav_file
42
 
43
- # βœ… Validate audio format
44
  if not speaker_wav or not os.path.exists(speaker_wav):
45
  return "Error: No valid speaker audio provided."
46
 
@@ -53,20 +56,19 @@ def change_aud(text: str, speaker_wav: str, speaker_wav_file: str) -> str:
53
  tts.tts_to_file(text, speaker_wav=speaker_wav, language="en", file_path=file_path)
54
 
55
  # βœ… Debugging print statement to confirm output generation
56
- if os.path.exists(file_path):
57
  print(f"Generated file path: {file_path}, Size: {os.path.getsize(file_path)} bytes")
 
58
  else:
59
- print("Error: Output file was not created.")
60
-
61
- return file_path
62
  except Exception as e:
63
  return f"Error generating cloned voice: {str(e)}"
64
 
65
  def show_error(text: str):
66
- # βœ… Ensure function returns expected outputs
67
  return (
68
  gr.update(visible=(text == ""), elem_id="warning", elem_classes="feedback"),
69
- gr.update(visible=(text != "")) # βœ… Fix: Second expected output value added
70
  )
71
 
72
  title = "Voice-Cloning-Demo"
 
30
  es_tts.to(device)
31
 
32
  def text_to_speech(text: str, speaker_wav: str, speaker_wav_file: str) -> str:
33
+ # βœ… Sanitize input text to avoid empty processing
34
+ text = text.strip().replace("\n", " ").replace(" ", " ")
35
+
36
  if not text:
37
  return "Error: No text provided."
38
 
 
43
  if speaker_wav_file and not speaker_wav:
44
  speaker_wav = speaker_wav_file
45
 
46
+ # βœ… Validate audio input
47
  if not speaker_wav or not os.path.exists(speaker_wav):
48
  return "Error: No valid speaker audio provided."
49
 
 
56
  tts.tts_to_file(text, speaker_wav=speaker_wav, language="en", file_path=file_path)
57
 
58
  # βœ… Debugging print statement to confirm output generation
59
+ if os.path.exists(file_path) and os.path.getsize(file_path) > 0:
60
  print(f"Generated file path: {file_path}, Size: {os.path.getsize(file_path)} bytes")
61
+ return file_path
62
  else:
63
+ return "Error: Output file was not properly generated."
 
 
64
  except Exception as e:
65
  return f"Error generating cloned voice: {str(e)}"
66
 
67
  def show_error(text: str):
68
+ # βœ… Ensure function returns expected outputs for Gradio UI updates
69
  return (
70
  gr.update(visible=(text == ""), elem_id="warning", elem_classes="feedback"),
71
+ gr.update(visible=(text != ""))
72
  )
73
 
74
  title = "Voice-Cloning-Demo"