File size: 2,362 Bytes
9f4bd77
055b6cb
 
ea674af
9f4bd77
055b6cb
 
 
 
 
ea674af
9f4bd77
055b6cb
 
 
9ead36c
055b6cb
 
 
ea674af
 
055b6cb
ea674af
9ead36c
055b6cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce0b765
 
055b6cb
 
 
 
 
 
 
 
 
 
ce0b765
055b6cb
 
 
 
 
ea674af
 
9ead36c
055b6cb
 
9ead36c
ce0b765
9ead36c
055b6cb
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import gradio as gr
import os
import soundfile as sf
from audio_processor import process_audio

def main():
    with gr.Blocks() as app:
        gr.Markdown(
            """
            # <div align="center"> diablofx Audio Interval Cutter (BETA) </div>
            Want to [support](https://ko-fi.com/diablofx) me?\n

            Need help with AI? [Join AI Hub!](https://discord.gg/aihub)
            """
        )

        with gr.Row():
            with gr.Column():
                audio_input = gr.File(label="Upload an audio file")
                interval_input = gr.Textbox("5000", label="Interval Length (in ms)")
                process_button = gr.Button(value='Start', variant='primary')
            with gr.Column():
                output_html = gr.HTML("Processed data will appear here")

        process_button.click(fn=process_audio_and_display_info, inputs=[audio_input, interval_input], outputs=output_html)

        app.queue(max_size=1022).launch(share=True)

def process_audio_and_display_info(audio_file, interval):
    # Get the audio file info
    audio_info = sf.info(audio_file)

    bit_depth = {'PCM_16': 16, 'FLOAT': 32}.get(audio_info.subtype, 0)

    # Convert duration to minutes, seconds, and milliseconds
    minutes, seconds = divmod(audio_info.duration, 60)
    seconds, milliseconds = divmod(seconds, 1)
    milliseconds *= 1000  # convert from seconds to milliseconds

    # Convert bitrate to kbp/s
    bitrate = audio_info.samplerate * audio_info.channels * bit_depth / 1000

    # Calculate speed in kbps
    speed_in_kbps = audio_info.samplerate * bit_depth / 1000

    # Create a table with the audio file info
    info_table = f"""
    | Information | Value |
    | :---: | :---: |
    | File Name | {os.path.basename(audio_file)} |
    | Duration | {int(minutes)} minutes - {int(seconds)} seconds - {int(milliseconds)} milliseconds |
    | Bitrate | {bitrate} kbp/s |
    | Audio Channels | {audio_info.channels} |
    | Samples per second | {audio_info.samplerate} Hz |
    | Bit per second | {audio_info.samplerate * audio_info.channels * bit_depth} bit/s |
    """

    # Process the audio file and get the download link
    download_link = process_audio(audio_file, interval)

    # Return the information table and the download link
    return info_table, download_link


if __name__ == "__main__":
    main()