Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,11 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
import os
|
|
|
|
|
4 |
from io import BytesIO
|
5 |
-
import
|
6 |
|
7 |
def get_audio_file_info(audio_file):
|
8 |
# Read the audio data from the file
|
@@ -39,31 +42,25 @@ def get_audio_file_info(audio_file):
|
|
39 |
# Return the info table
|
40 |
return info_table
|
41 |
|
42 |
-
def
|
43 |
# Read the audio data from the file
|
44 |
-
|
45 |
|
46 |
-
# Calculate the
|
47 |
-
|
48 |
-
num_parts = math.ceil(total_length / (duration * 1000))
|
49 |
|
50 |
-
#
|
51 |
-
|
52 |
-
os.makedirs(output_folder, exist_ok=True)
|
53 |
|
54 |
-
#
|
55 |
output_files = []
|
56 |
-
for i in
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
output_path = os.path.join(output_folder, f"part_{i + 1}.mp3")
|
61 |
-
split_audio.export(output_path, format="mp3")
|
62 |
-
output_files.append(output_path)
|
63 |
|
64 |
return output_files
|
65 |
|
66 |
-
|
67 |
def main():
|
68 |
# Gradio Interface
|
69 |
with gr.Blocks() as app:
|
@@ -72,17 +69,19 @@ def main():
|
|
72 |
# <div align="center"> diablofx Audio Interval Cutter (BETA) </div>
|
73 |
Want to [support](https://ko-fi.com/diablofx) me? Or [join AI HUB](https://discord.gg/aihub) for more Help!\n
|
74 |
"""
|
75 |
-
|
76 |
with gr.Row():
|
77 |
with gr.Column():
|
78 |
-
audio_input = gr.Audio(type='filepath'
|
|
|
79 |
split_audio_butt = gr.Button(value='Split Audio into 5s Clips', variant='success')
|
80 |
with gr.Column():
|
81 |
-
|
82 |
|
83 |
-
|
|
|
84 |
|
85 |
app.queue(max_size=1022).launch()
|
86 |
|
87 |
# Create the Gradio interface
|
88 |
-
main()
|
|
|
1 |
+
|
2 |
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
import os
|
5 |
+
import soundfile as sf
|
6 |
+
from pydub import AudioSegment
|
7 |
from io import BytesIO
|
8 |
+
import torchaudio
|
9 |
|
10 |
def get_audio_file_info(audio_file):
|
11 |
# Read the audio data from the file
|
|
|
42 |
# Return the info table
|
43 |
return info_table
|
44 |
|
45 |
+
def split_audio_into_clips(audio_file):
|
46 |
# Read the audio data from the file
|
47 |
+
audio_data, sample_rate = torchaudio.load(audio_file, normalize=True)
|
48 |
|
49 |
+
# Calculate the duration of each 5-second segment
|
50 |
+
segment_duration = 5 * sample_rate
|
|
|
51 |
|
52 |
+
# Split the audio into segments
|
53 |
+
segments = [audio_data[:, i:i+segment_duration] for i in range(0, audio_data.size(1), segment_duration)]
|
|
|
54 |
|
55 |
+
# Save each segment to a separate file
|
56 |
output_files = []
|
57 |
+
for i, segment in enumerate(segments):
|
58 |
+
output_file = f"output_segment_{i+1}.wav"
|
59 |
+
torchaudio.save(output_file, segment, sample_rate)
|
60 |
+
output_files.append(output_file)
|
|
|
|
|
|
|
61 |
|
62 |
return output_files
|
63 |
|
|
|
64 |
def main():
|
65 |
# Gradio Interface
|
66 |
with gr.Blocks() as app:
|
|
|
69 |
# <div align="center"> diablofx Audio Interval Cutter (BETA) </div>
|
70 |
Want to [support](https://ko-fi.com/diablofx) me? Or [join AI HUB](https://discord.gg/aihub) for more Help!\n
|
71 |
"""
|
72 |
+
)
|
73 |
with gr.Row():
|
74 |
with gr.Column():
|
75 |
+
audio_input = gr.Audio(type='filepath')
|
76 |
+
create_info_butt = gr.Button(value='Get Audio File Info', variant='primary')
|
77 |
split_audio_butt = gr.Button(value='Split Audio into 5s Clips', variant='success')
|
78 |
with gr.Column():
|
79 |
+
output_markdown = gr.Markdown(value="", visible=True)
|
80 |
|
81 |
+
create_info_butt.click(fn=get_audio_file_info, inputs=[audio_input], outputs=[output_markdown])
|
82 |
+
split_audio_butt.click(fn=split_audio_into_clips, inputs=[audio_input])
|
83 |
|
84 |
app.queue(max_size=1022).launch()
|
85 |
|
86 |
# Create the Gradio interface
|
87 |
+
main()
|