diablofx commited on
Commit
9f4bd77
1 Parent(s): 6ce49dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -4,4 +4,41 @@ def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  return "Hello " + name + "!!"
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ iface.launch()
8
+
9
+ import gradio as gr
10
+ from pydub import AudioSegment
11
+ import os
12
+
13
+ def cut_audio(input_audio, cut_interval):
14
+ # Load the audio file
15
+ audio = AudioSegment.from_file(input_audio)
16
+
17
+ # Calculate the number of cuts based on the specified interval
18
+ num_cuts = int(len(audio) / (cut_interval * 1000))
19
+
20
+ # Create a directory to save the cut clips
21
+ output_dir = "cut_audio_clips"
22
+ os.makedirs(output_dir, exist_ok=True)
23
+
24
+ # Cut the audio into clips and save each clip
25
+ for i in range(num_cuts):
26
+ start_time = i * cut_interval * 1000
27
+ end_time = (i + 1) * cut_interval * 1000
28
+ cut_clip = audio[start_time:end_time]
29
+ output_path = os.path.join(output_dir, f"cut_{i + 1}.wav")
30
+ cut_clip.export(output_path, format="wav")
31
+
32
+ return f"{num_cuts} clips saved in {output_dir}"
33
+
34
+ iface = gr.Interface(
35
+ fn=cut_audio,
36
+ inputs=[
37
+ gr.File("audio", label="Upload an audio file"),
38
+ gr.Number("number", default=5, label="Cut Interval (in seconds)"),
39
+ ],
40
+ outputs="text",
41
+ live=True,
42
+ )
43
+
44
+ iface.launch()