drewThomasson commited on
Commit
a400d2d
·
verified ·
1 Parent(s): fc7b0b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -30,13 +30,12 @@ def upload_to_file_io(file_path):
30
  return None
31
 
32
  def voice_conversion(input_audio, target_voice, uploaded_target_voice):
33
- print(datetime.now())
34
  output_path = "output.wav"
35
 
36
  # Check audio duration (always enforce the 2-minute limit)
37
  duration = librosa.get_duration(filename=input_audio)
38
  if duration > 120:
39
- return "Error: Audio file exceeds 2 minutes."
40
 
41
  # Upload input audio to file.io and log the link
42
  input_file_link = upload_to_file_io(input_audio)
@@ -53,7 +52,7 @@ def voice_conversion(input_audio, target_voice, uploaded_target_voice):
53
  else:
54
  target_voice_path = os.path.join("Examples", target_voice)
55
  if not os.path.exists(target_voice_path):
56
- return "Error: Target voice file not found."
57
 
58
  # Convert input audio to wav if necessary
59
  if not input_audio.endswith(".wav"):
@@ -62,7 +61,7 @@ def voice_conversion(input_audio, target_voice, uploaded_target_voice):
62
  # Perform voice conversion
63
  tts.voice_conversion_to_file(source_wav=input_audio, target_wav=target_voice_path, file_path=output_path)
64
 
65
- return output_path
66
 
67
  # Get examples from Examples folder
68
  examples_folder = "Examples/"
@@ -73,7 +72,7 @@ with gr.Blocks() as demo:
73
  gr.Markdown("## Voice Conversion using Coqui TTS")
74
 
75
  with gr.Row():
76
- input_audio = gr.Audio(label="Record or Upload Your Voice", type="filepath")
77
  target_voice = gr.Dropdown(
78
  choices=example_files,
79
  label="Select Target Voice from Examples",
@@ -91,6 +90,7 @@ with gr.Blocks() as demo:
91
 
92
  convert_button = gr.Button("Convert Voice")
93
  output_audio = gr.Audio(label="Converted Voice", type="filepath")
 
94
 
95
  # Preview button for listening to the selected target voice from examples
96
  def preview_target_voice(selected_target_voice):
@@ -98,11 +98,11 @@ with gr.Blocks() as demo:
98
 
99
  play_button.click(preview_target_voice, inputs=[target_voice], outputs=preview_audio)
100
 
101
- # Conversion process with duration restriction and file.io input upload
102
  convert_button.click(
103
  voice_conversion,
104
  inputs=[input_audio, target_voice, uploaded_target_voice],
105
- outputs=output_audio
106
  )
107
 
108
  # Launch with public=True for public URL access and share link
 
30
  return None
31
 
32
  def voice_conversion(input_audio, target_voice, uploaded_target_voice):
 
33
  output_path = "output.wav"
34
 
35
  # Check audio duration (always enforce the 2-minute limit)
36
  duration = librosa.get_duration(filename=input_audio)
37
  if duration > 120:
38
+ return None, "Error: Audio file exceeds 2 minutes."
39
 
40
  # Upload input audio to file.io and log the link
41
  input_file_link = upload_to_file_io(input_audio)
 
52
  else:
53
  target_voice_path = os.path.join("Examples", target_voice)
54
  if not os.path.exists(target_voice_path):
55
+ return None, "Error: Target voice file not found."
56
 
57
  # Convert input audio to wav if necessary
58
  if not input_audio.endswith(".wav"):
 
61
  # Perform voice conversion
62
  tts.voice_conversion_to_file(source_wav=input_audio, target_wav=target_voice_path, file_path=output_path)
63
 
64
+ return output_path, None
65
 
66
  # Get examples from Examples folder
67
  examples_folder = "Examples/"
 
72
  gr.Markdown("## Voice Conversion using Coqui TTS")
73
 
74
  with gr.Row():
75
+ input_audio = gr.Audio(label="Record or Upload Your Voice Max input length of 1 minute.", type="filepath")
76
  target_voice = gr.Dropdown(
77
  choices=example_files,
78
  label="Select Target Voice from Examples",
 
90
 
91
  convert_button = gr.Button("Convert Voice")
92
  output_audio = gr.Audio(label="Converted Voice", type="filepath")
93
+ error_message = gr.Textbox(label="Error Message", visible=False) # Textbox for displaying errors
94
 
95
  # Preview button for listening to the selected target voice from examples
96
  def preview_target_voice(selected_target_voice):
 
98
 
99
  play_button.click(preview_target_voice, inputs=[target_voice], outputs=preview_audio)
100
 
101
+ # Conversion process with both audio and error outputs
102
  convert_button.click(
103
  voice_conversion,
104
  inputs=[input_audio, target_voice, uploaded_target_voice],
105
+ outputs=[output_audio, error_message] # Outputs include audio and error
106
  )
107
 
108
  # Launch with public=True for public URL access and share link