Spaces:
Runtime error
Runtime error
TheStinger
commited on
Commit
•
9770bf5
1
Parent(s):
1027755
Update app.py
Browse files
app.py
CHANGED
@@ -6,29 +6,20 @@ import soundfile as sf
|
|
6 |
import requests
|
7 |
|
8 |
def download_file(url):
|
9 |
-
# Estrai l'ID del file dal link di Google Drive
|
10 |
file_id = url.split('/')[-2]
|
11 |
-
|
12 |
-
# Crea il link di download diretto
|
13 |
download_url = f'https://docs.google.com/uc?export=download&id={file_id}'
|
14 |
-
|
15 |
-
# Scarica il file
|
16 |
response = requests.get(download_url, allow_redirects=True)
|
17 |
local_filename = url.split('/')[-1] + '.wav'
|
18 |
open(local_filename, 'wb').write(response.content)
|
19 |
-
|
20 |
return local_filename
|
21 |
|
22 |
def main():
|
23 |
-
# Gradio Interface
|
24 |
with gr.Blocks() as app:
|
25 |
gr.Markdown(
|
26 |
"""
|
27 |
-
|
28 |
-
Audio Analyzer Software by Ilaria, Help me on [Ko-Fi!](https://ko-fi.com/ilariaowo)\n
|
29 |
Special thanks to Alex Murkoff for helping me coding it!
|
30 |
-
|
31 |
-
Need help with AI? Join [Join AI Hub!](https://discord.gg/aihub)
|
32 |
"""
|
33 |
)
|
34 |
|
@@ -54,40 +45,21 @@ def main():
|
|
54 |
app.queue(max_size=1022).launch(share=True)
|
55 |
|
56 |
def create_spectrogram_and_get_info(audio_file):
|
57 |
-
# Clear figure in case it has data in it
|
58 |
plt.clf()
|
59 |
-
|
60 |
-
# Read the audio data from the file
|
61 |
audio_data, sample_rate = sf.read(audio_file)
|
62 |
-
|
63 |
-
# Convert to mono if it's not mono
|
64 |
if len(audio_data.shape) > 1:
|
65 |
audio_data = np.mean(audio_data, axis=1)
|
66 |
-
|
67 |
-
# Create the spectrogram
|
68 |
plt.specgram(audio_data, Fs=sample_rate / 1, NFFT=4096, sides='onesided',
|
69 |
cmap="inferno", scale_by_freq=True, scale='dB', mode='magnitude', window=np.hanning(4096))
|
70 |
-
|
71 |
-
# Save the spectrogram to a PNG file
|
72 |
plt.savefig('spectrogram.png')
|
73 |
-
|
74 |
-
# Get the audio file info
|
75 |
audio_info = sf.info(audio_file)
|
76 |
-
|
77 |
bit_depth = {'PCM_16': 16, 'FLOAT': 32}.get(audio_info.subtype, 0)
|
78 |
-
|
79 |
-
# Convert duration to minutes, seconds, and milliseconds
|
80 |
minutes, seconds = divmod(audio_info.duration, 60)
|
81 |
seconds, milliseconds = divmod(seconds, 1)
|
82 |
-
milliseconds *= 1000
|
83 |
-
|
84 |
-
# Convert bitrate to mb/s
|
85 |
bitrate = audio_info.samplerate * audio_info.channels * bit_depth / 8 / 1024 / 1024
|
86 |
-
|
87 |
-
# Calculate speed in kbps
|
88 |
speed_in_kbps = audio_info.samplerate * bit_depth / 1000
|
89 |
-
|
90 |
-
# Create a table with the audio file info
|
91 |
filename_without_extension, _ = os.path.splitext(os.path.basename(audio_file))
|
92 |
info_table = f"""
|
93 |
|
|
|
6 |
import requests
|
7 |
|
8 |
def download_file(url):
|
|
|
9 |
file_id = url.split('/')[-2]
|
|
|
|
|
10 |
download_url = f'https://docs.google.com/uc?export=download&id={file_id}'
|
|
|
|
|
11 |
response = requests.get(download_url, allow_redirects=True)
|
12 |
local_filename = url.split('/')[-1] + '.wav'
|
13 |
open(local_filename, 'wb').write(response.content)
|
|
|
14 |
return local_filename
|
15 |
|
16 |
def main():
|
|
|
17 |
with gr.Blocks() as app:
|
18 |
gr.Markdown(
|
19 |
"""
|
20 |
+
Audio Analyzer Software by Ilaria, Help me on Ko-Fi!\n
|
|
|
21 |
Special thanks to Alex Murkoff for helping me coding it!
|
22 |
+
Need help with AI? Join Join AI Hub!
|
|
|
23 |
"""
|
24 |
)
|
25 |
|
|
|
45 |
app.queue(max_size=1022).launch(share=True)
|
46 |
|
47 |
def create_spectrogram_and_get_info(audio_file):
|
|
|
48 |
plt.clf()
|
49 |
+
plt.figure(figsize=(15, 5))
|
|
|
50 |
audio_data, sample_rate = sf.read(audio_file)
|
|
|
|
|
51 |
if len(audio_data.shape) > 1:
|
52 |
audio_data = np.mean(audio_data, axis=1)
|
|
|
|
|
53 |
plt.specgram(audio_data, Fs=sample_rate / 1, NFFT=4096, sides='onesided',
|
54 |
cmap="inferno", scale_by_freq=True, scale='dB', mode='magnitude', window=np.hanning(4096))
|
|
|
|
|
55 |
plt.savefig('spectrogram.png')
|
|
|
|
|
56 |
audio_info = sf.info(audio_file)
|
|
|
57 |
bit_depth = {'PCM_16': 16, 'FLOAT': 32}.get(audio_info.subtype, 0)
|
|
|
|
|
58 |
minutes, seconds = divmod(audio_info.duration, 60)
|
59 |
seconds, milliseconds = divmod(seconds, 1)
|
60 |
+
milliseconds *= 1000
|
|
|
|
|
61 |
bitrate = audio_info.samplerate * audio_info.channels * bit_depth / 8 / 1024 / 1024
|
|
|
|
|
62 |
speed_in_kbps = audio_info.samplerate * bit_depth / 1000
|
|
|
|
|
63 |
filename_without_extension, _ = os.path.splitext(os.path.basename(audio_file))
|
64 |
info_table = f"""
|
65 |
|