audioo / app.py
akashdeb's picture
Update app.py
1130f77 verified
import gradio as gr
import os
def display_audio_meter(audio_file):
# Convert file path to a URL that can be used in the HTML and JavaScript
audio_url = f"/file={audio_file}"
# Embed the HTML for the audio meter visualization using wavesurfer.js
html_code = f"""
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/wavesurfer.js"></script>
<div id="audio-meter" style="width: 100%; height: 128px; background-color: #f0f0f0;"></div>
<script>
const audioFile = '{audio_url}'; // Use the audio file URL in the script
const waveSurfer = WaveSurfer.create({{
container: '#audio-meter',
waveColor: 'blue',
progressColor: 'green',
height: 128
}});
waveSurfer.load(audioFile); // Load the audio file in the waveform
</script>
</body>
</html>
"""
return html_code
# Create Gradio Interface with a Submit button
with gr.Blocks() as interface:
# Audio input
audio_input = gr.Audio(type="filepath")
# Submit button
submit_button = gr.Button("Submit")
# Output area
output = gr.HTML()
# Button click triggers the audio meter display
submit_button.click(fn=display_audio_meter, inputs=audio_input, outputs=output)
# Launch the interface
interface.launch(share=True)