Spaces:
Runtime error
Runtime error
File size: 1,150 Bytes
de60a6a 458da1c 5a86410 eb0bc41 ac0ec53 458da1c ac0ec53 6af81aa 458da1c 6af81aa 458da1c 6af81aa 5a86410 458da1c 5a86410 de60a6a |
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 |
import gradio as gr
import matplotlib.pyplot as plt
import numpy as np
import os
import soundfile as sf
def create_spectrogram(audio_data, sample_rate):
# Crea lo spettrogramma
plt.specgram(audio_data, Fs=sample_rate)
# Salva lo spettrogramma in un file PNG
plt.savefig('spectrogram.png')
# Ritorna il file PNG dello spettrogramma
return 'spectrogram.png'
def get_audio_info(audio_file):
# Ottieni le informazioni del file audio
audio_info = sf.info(audio_file.name)
# Crea una tabella con le informazioni del file audio
info_table = f"""
| Informazione | Valore |
| --- | --- |
| Durata | {audio_info.duration} secondi |
| Campioni al secondo | {audio_info.samplerate} Hz |
| Canali | {audio_info.channels} |
| Bitrate | {audio_info.samplerate * audio_info.channels * audio_info.subtype.itemsize * 8} bit/s |
| Estensione | {os.path.splitext(audio_file.name)[1]} |
"""
return info_table
# Crea l'interfaccia Gradio
iface = gr.Interface(
fn=[get_audio_info, create_spectrogram],
inputs=gr.Audio(),
outputs=["markdown", "image"]
)
iface.launch()
|