Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -41,24 +41,29 @@ def get_audio_file_info(audio_file):
|
|
41 |
# Return the info table
|
42 |
return info_table
|
43 |
|
44 |
-
def
|
45 |
# Read the audio data from the file
|
46 |
-
|
47 |
|
48 |
-
# Calculate the
|
49 |
-
|
|
|
50 |
|
51 |
-
#
|
52 |
-
|
|
|
53 |
|
54 |
-
#
|
55 |
-
|
56 |
-
for i
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
60 |
|
61 |
-
return
|
62 |
|
63 |
def main():
|
64 |
# Gradio Interface
|
@@ -69,16 +74,14 @@ def main():
|
|
69 |
Want to [support](https://ko-fi.com/diablofx) me? Or [join AI HUB](https://discord.gg/aihub) for more Help!\n
|
70 |
"""
|
71 |
)
|
72 |
-
|
73 |
with gr.Column():
|
74 |
-
audio_input = gr.Audio(type='
|
75 |
-
create_info_butt = gr.Button(value='Get Audio File Info', variant='primary')
|
76 |
split_audio_butt = gr.Button(value='Split Audio into 5s Clips', variant='success')
|
77 |
with gr.Column():
|
78 |
-
|
79 |
|
80 |
-
|
81 |
-
split_audio_butt.click(fn=split_audio_into_clips, inputs=[audio_input], outputs=[output_markdown])
|
82 |
|
83 |
app.queue(max_size=1022).launch()
|
84 |
|
|
|
41 |
# Return the info table
|
42 |
return info_table
|
43 |
|
44 |
+
def split_audio(input_file, duration):
|
45 |
# Read the audio data from the file
|
46 |
+
audio = AudioSegment.from_file(input_file)
|
47 |
|
48 |
+
# Calculate the total length and the number of parts
|
49 |
+
total_length = len(audio)
|
50 |
+
num_parts = math.ceil(total_length / (duration * 1000))
|
51 |
|
52 |
+
# Create a folder to store the split audio files
|
53 |
+
output_folder = "output"
|
54 |
+
os.makedirs(output_folder, exist_ok=True)
|
55 |
|
56 |
+
# Split the audio and save each part
|
57 |
+
output_files = []
|
58 |
+
for i in range(num_parts):
|
59 |
+
start = i * duration * 1000
|
60 |
+
end = (i + 1) * duration * 1000
|
61 |
+
split_audio = audio[start:end]
|
62 |
+
output_path = os.path.join(output_folder, f"part_{i + 1}.mp3")
|
63 |
+
split_audio.export(output_path, format="mp3")
|
64 |
+
output_files.append(output_path)
|
65 |
|
66 |
+
return output_files
|
67 |
|
68 |
def main():
|
69 |
# Gradio Interface
|
|
|
74 |
Want to [support](https://ko-fi.com/diablofx) me? Or [join AI HUB](https://discord.gg/aihub) for more Help!\n
|
75 |
"""
|
76 |
)
|
77 |
+
with gr.Row():
|
78 |
with gr.Column():
|
79 |
+
audio_input = gr.Audio(type='file', label="Upload Audio File")
|
|
|
80 |
split_audio_butt = gr.Button(value='Split Audio into 5s Clips', variant='success')
|
81 |
with gr.Column():
|
82 |
+
output_text = gr.Textbox(value="", label="Output Files", disabled=True)
|
83 |
|
84 |
+
split_audio_butt.click(fn=split_audio, inputs=[audio_input], outputs=[output_text])
|
|
|
85 |
|
86 |
app.queue(max_size=1022).launch()
|
87 |
|