Spaces:
Runtime error
Runtime error
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() | |