szili2011 commited on
Commit
2b6bee1
·
verified ·
1 Parent(s): 543c357

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -67,13 +67,16 @@ def generate_sfx(text, duration=30):
67
 
68
  # Calculate total samples for the specified duration
69
  total_samples = duration * 22050 # Samples for 30 seconds
 
70
  # Generate audio samples
71
  generated_samples = model.predict(input_data)
72
 
73
- # Check the length of generated samples and ensure it meets the required duration
74
- if len(generated_samples) < total_samples:
75
- raise ValueError(f"Generated audio is shorter than {duration} seconds.")
76
-
 
 
77
  # Convert the prediction to audio data
78
  audio_data = convert_to_audio(generated_samples)
79
 
@@ -83,12 +86,12 @@ def generate_sfx(text, duration=30):
83
 
84
  return output_filename
85
 
86
- # Define the Gradio interface
87
  interface = gr.Interface(
88
  fn=generate_sfx,
89
  inputs=[
90
  gr.Textbox(label="Enter a Word", placeholder="Write a Word To Convert it into SFX Sound"),
91
- gr.Slider(label="Duration (seconds)", minimum=30, maximum=120, value=30) # Set duration options
92
  ],
93
  outputs=gr.Audio(label="Generated SFX", type="filepath"),
94
  live=False,
 
67
 
68
  # Calculate total samples for the specified duration
69
  total_samples = duration * 22050 # Samples for 30 seconds
70
+
71
  # Generate audio samples
72
  generated_samples = model.predict(input_data)
73
 
74
+ # Ensure generated samples meet the required duration
75
+ if generated_samples.shape[1] < total_samples:
76
+ # Pad with zeros if not enough audio is generated
77
+ padding = np.zeros((1, total_samples - generated_samples.shape[1]))
78
+ generated_samples = np.concatenate([generated_samples, padding], axis=1)
79
+
80
  # Convert the prediction to audio data
81
  audio_data = convert_to_audio(generated_samples)
82
 
 
86
 
87
  return output_filename
88
 
89
+ # Define the Gradio interface with updated slider settings
90
  interface = gr.Interface(
91
  fn=generate_sfx,
92
  inputs=[
93
  gr.Textbox(label="Enter a Word", placeholder="Write a Word To Convert it into SFX Sound"),
94
+ gr.Slider(label="Duration (seconds)", minimum=2, maximum=20, value=5) # Set duration options
95
  ],
96
  outputs=gr.Audio(label="Generated SFX", type="filepath"),
97
  live=False,