File size: 1,216 Bytes
6ce49dd
 
 
 
 
 
9f4bd77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr

def greet(name):
    return "Hello " + name + "!!"

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()

import gradio as gr
from pydub import AudioSegment
import os

def cut_audio(input_audio, cut_interval):
    # Load the audio file
    audio = AudioSegment.from_file(input_audio)

    # Calculate the number of cuts based on the specified interval
    num_cuts = int(len(audio) / (cut_interval * 1000))

    # Create a directory to save the cut clips
    output_dir = "cut_audio_clips"
    os.makedirs(output_dir, exist_ok=True)

    # Cut the audio into clips and save each clip
    for i in range(num_cuts):
        start_time = i * cut_interval * 1000
        end_time = (i + 1) * cut_interval * 1000
        cut_clip = audio[start_time:end_time]
        output_path = os.path.join(output_dir, f"cut_{i + 1}.wav")
        cut_clip.export(output_path, format="wav")

    return f"{num_cuts} clips saved in {output_dir}"

iface = gr.Interface(
    fn=cut_audio,
    inputs=[
        gr.File("audio", label="Upload an audio file"),
        gr.Number("number", default=5, label="Cut Interval (in seconds)"),
    ],
    outputs="text",
    live=True,
)

iface.launch()