Spaces:
Runtime error
Runtime error
TheStinger
commited on
Commit
·
41bada8
1
Parent(s):
7161888
Update app.py
Browse files
app.py
CHANGED
@@ -4,17 +4,13 @@ import numpy as np
|
|
4 |
import os
|
5 |
import soundfile as sf
|
6 |
|
7 |
-
def
|
8 |
# Crea lo spettrogramma
|
9 |
plt.specgram(audio_data, Fs=sample_rate)
|
10 |
|
11 |
# Salva lo spettrogramma in un file PNG
|
12 |
plt.savefig('spectrogram.png')
|
13 |
|
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 |
|
@@ -28,13 +24,10 @@ def get_audio_info(audio_file):
|
|
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 |
-
|
|
|
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()
|
|
|
4 |
import os
|
5 |
import soundfile as sf
|
6 |
|
7 |
+
def create_spectrogram_and_get_info(audio_data, sample_rate):
|
8 |
# Crea lo spettrogramma
|
9 |
plt.specgram(audio_data, Fs=sample_rate)
|
10 |
|
11 |
# Salva lo spettrogramma in un file PNG
|
12 |
plt.savefig('spectrogram.png')
|
13 |
|
|
|
|
|
|
|
|
|
14 |
# Ottieni le informazioni del file audio
|
15 |
audio_info = sf.info(audio_file.name)
|
16 |
|
|
|
24 |
| Bitrate | {audio_info.samplerate * audio_info.channels * audio_info.subtype.itemsize * 8} bit/s |
|
25 |
| Estensione | {os.path.splitext(audio_file.name)[1]} |
|
26 |
"""
|
27 |
+
|
28 |
+
# Ritorna il file PNG dello spettrogramma e la tabella delle informazioni
|
29 |
+
return info_table, 'spectrogram.png'
|
30 |
|
31 |
# Crea l'interfaccia Gradio
|
32 |
+
iface = gr.Interface(fn=create_spectrogram_and_get_info, inputs=gr.Audio(), outputs=["markdown", "image"])
|
|
|
|
|
|
|
|
|
33 |
iface.launch()
|