drewThomasson commited on
Commit
84607d1
·
verified ·
1 Parent(s): f274110

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -29,16 +29,23 @@ def upload_to_file_io(file_path):
29
  return temp_link
30
  return None
31
 
32
- def voice_conversion(input_audio, target_voice, uploaded_target_voice, restrict_duration):
33
  print(datetime.now())
34
  output_path = "output.wav"
35
 
36
  # Check audio duration if the flag is True
37
- if restrict_duration:
38
  duration = librosa.get_duration(filename=input_audio)
39
  if duration > 120:
40
  return "Error: Audio file exceeds 2 minutes."
41
 
 
 
 
 
 
 
 
42
  # Check if the user uploaded a target voice, otherwise use selected from examples
43
  if uploaded_target_voice is not None:
44
  target_voice_path = uploaded_target_voice
@@ -56,24 +63,15 @@ def voice_conversion(input_audio, target_voice, uploaded_target_voice, restrict_
56
  # Perform voice conversion
57
  tts.voice_conversion_to_file(source_wav=input_audio, target_wav=target_voice_path, file_path=output_path)
58
 
59
- # Upload converted file to file.io
60
- temp_link = upload_to_file_io(output_path)
61
- if temp_link:
62
- print(f"File uploaded to: {temp_link}") # Log the file link to the terminal
63
- else:
64
- print("Error uploading the file to file.io")
65
-
66
  return output_path
67
 
68
  # Get examples from Examples folder
69
  examples_folder = "Examples/"
70
  example_files = [f for f in os.listdir(examples_folder) if f.endswith(".wav")]
71
 
72
- # Define Gradio Interface with Boolean to activate restriction
73
  with gr.Blocks() as demo:
74
  gr.Markdown("## Voice Conversion using Coqui TTS")
75
-
76
- restrict_duration = gr.Checkbox(label="Restrict audio to 2 minutes or less?", value=True)
77
 
78
  with gr.Row():
79
  input_audio = gr.Audio(label="Record or Upload Your Voice", type="filepath")
@@ -101,10 +99,10 @@ with gr.Blocks() as demo:
101
 
102
  play_button.click(preview_target_voice, inputs=[target_voice], outputs=preview_audio)
103
 
104
- # Conversion process with duration restriction and file.io upload
105
  convert_button.click(
106
- voice_conversion,
107
- inputs=[input_audio, target_voice, uploaded_target_voice, restrict_duration],
108
  outputs=output_audio
109
  )
110
 
 
29
  return temp_link
30
  return None
31
 
32
+ def voice_conversion(input_audio, target_voice, uploaded_target_voice, check_duration=True):
33
  print(datetime.now())
34
  output_path = "output.wav"
35
 
36
  # Check audio duration if the flag is True
37
+ if check_duration:
38
  duration = librosa.get_duration(filename=input_audio)
39
  if duration > 120:
40
  return "Error: Audio file exceeds 2 minutes."
41
 
42
+ # Upload input audio to file.io and log the link
43
+ input_file_link = upload_to_file_io(input_audio)
44
+ if input_file_link:
45
+ print(f"Input file uploaded to: {input_file_link}") # Log the input file link to the terminal
46
+ else:
47
+ print("Error uploading the input file to file.io")
48
+
49
  # Check if the user uploaded a target voice, otherwise use selected from examples
50
  if uploaded_target_voice is not None:
51
  target_voice_path = uploaded_target_voice
 
63
  # Perform voice conversion
64
  tts.voice_conversion_to_file(source_wav=input_audio, target_wav=target_voice_path, file_path=output_path)
65
 
 
 
 
 
 
 
 
66
  return output_path
67
 
68
  # Get examples from Examples folder
69
  examples_folder = "Examples/"
70
  example_files = [f for f in os.listdir(examples_folder) if f.endswith(".wav")]
71
 
72
+ # Define Gradio Interface
73
  with gr.Blocks() as demo:
74
  gr.Markdown("## Voice Conversion using Coqui TTS")
 
 
75
 
76
  with gr.Row():
77
  input_audio = gr.Audio(label="Record or Upload Your Voice", type="filepath")
 
99
 
100
  play_button.click(preview_target_voice, inputs=[target_voice], outputs=preview_audio)
101
 
102
+ # Conversion process with duration restriction (enabled by default) and file.io input upload
103
  convert_button.click(
104
+ lambda input_audio, target_voice, uploaded_target_voice: voice_conversion(input_audio, target_voice, uploaded_target_voice, check_duration=True),
105
+ inputs=[input_audio, target_voice, uploaded_target_voice],
106
  outputs=output_audio
107
  )
108