Spaces:
Runtime error
Runtime error
TheStinger
commited on
Commit
·
5a86410
1
Parent(s):
b894c33
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import matplotlib.pyplot as plt
|
3 |
import numpy as np
|
4 |
-
|
|
|
5 |
|
6 |
def create_spectrogram(audio_data, sample_rate):
|
7 |
# Crea lo spettrogramma
|
@@ -13,6 +14,27 @@ def create_spectrogram(audio_data, sample_rate):
|
|
13 |
# Ritorna il file PNG dello spettrogramma
|
14 |
return 'spectrogram.png'
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Crea l'interfaccia Gradio
|
17 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
18 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import matplotlib.pyplot as plt
|
3 |
import numpy as np
|
4 |
+
import os
|
5 |
+
import soundfile as sf
|
6 |
|
7 |
def create_spectrogram(audio_data, sample_rate):
|
8 |
# Crea lo spettrogramma
|
|
|
14 |
# Ritorna il file PNG dello spettrogramma
|
15 |
return 'spectrogram.png'
|
16 |
|
17 |
+
def get_audio_info(audio_file):
|
18 |
+
# Ottieni le informazioni del file audio
|
19 |
+
audio_info = sf.info(audio_file.name)
|
20 |
+
|
21 |
+
# Crea una tabella con le informazioni del file audio
|
22 |
+
info_table = f"""
|
23 |
+
| Informazione | Valore |
|
24 |
+
| --- | --- |
|
25 |
+
| Durata | {audio_info.duration} secondi |
|
26 |
+
| Campioni al secondo | {audio_info.samplerate} Hz |
|
27 |
+
| Canali | {audio_info.channels} |
|
28 |
+
| Bitrate | {audio_info.samplerate * audio_info.channels * audio_info.subtype.itemsize * 8} bit/s |
|
29 |
+
| Estensione | {os.path.splitext(audio_file.name)[1]} |
|
30 |
+
"""
|
31 |
+
|
32 |
+
return info_table
|
33 |
+
|
34 |
# Crea l'interfaccia Gradio
|
35 |
+
iface = gr.Interface(
|
36 |
+
fn=[get_audio_info, create_spectrogram],
|
37 |
+
inputs=gr.Audio(),
|
38 |
+
outputs=["markdown", "image"]
|
39 |
+
)
|
40 |
iface.launch()
|