TheStinger commited on
Commit
0166575
1 Parent(s): 66a5579

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -8
app.py CHANGED
@@ -5,7 +5,6 @@ import os
5
  import soundfile as sf
6
 
7
  def create_spectrogram_and_get_info(audio_file):
8
-
9
  # Clear figure in case it has data in it
10
  plt.clf()
11
 
@@ -27,15 +26,31 @@ def create_spectrogram_and_get_info(audio_file):
27
 
28
  bit_depth = {'PCM_16': 16, 'FLOAT': 32}.get(audio_info.subtype, 0)
29
 
 
 
 
 
 
 
 
 
30
  # Create a table with the audio file info
31
  info_table = f"""
32
- | Informazione | Valore |
 
 
 
 
 
 
 
 
33
  | --- | --- |
34
- | Durata | {audio_info.duration} secondi |
35
- | Campioni al secondo | {audio_info.samplerate} Hz |
36
- | Canali | {audio_info.channels} |
37
- | Bitrate | {audio_info.samplerate * audio_info.channels * bit_depth} bit/s |
38
- | Estensione | {os.path.splitext(audio_file)[1]} |
39
  """
40
 
41
  # Return the PNG file of the spectrogram and the info table
@@ -44,4 +59,3 @@ def create_spectrogram_and_get_info(audio_file):
44
  # Create the Gradio interface
45
  iface = gr.Interface(fn=create_spectrogram_and_get_info, inputs=gr.Audio(type="filepath"), outputs=["markdown", "image"])
46
  iface.launch()
47
-
 
5
  import soundfile as sf
6
 
7
  def create_spectrogram_and_get_info(audio_file):
 
8
  # Clear figure in case it has data in it
9
  plt.clf()
10
 
 
26
 
27
  bit_depth = {'PCM_16': 16, 'FLOAT': 32}.get(audio_info.subtype, 0)
28
 
29
+ # Convert duration to minutes, seconds, and milliseconds
30
+ minutes, seconds = divmod(audio_info.duration, 60)
31
+ seconds, milliseconds = divmod(seconds, 1)
32
+ milliseconds *= 1000 # convert from seconds to milliseconds
33
+
34
+ # Convert bitrate to Mb/s
35
+ bitrate = audio_info.samplerate * audio_info.channels * bit_depth / 8 / 1024 / 1024
36
+
37
  # Create a table with the audio file info
38
  info_table = f"""
39
+ # Ilaria Audio Analyzer 💖
40
+
41
+ Audio Analyzer Software by Ilaria, Help me on Ko-Fi
42
+
43
+ Special thanks to Alex Murkoff for helping me coding it!
44
+
45
+ Need help with AI? Join AI Hub!
46
+
47
+ | Information | Value |
48
  | --- | --- |
49
+ | Duration | {int(minutes)} minutes - {int(seconds)} seconds - {int(milliseconds)} milliseconds |
50
+ | Samples per second | {audio_info.samplerate} Hz |
51
+ | Audio Channels | {audio_info.channels} |
52
+ | Bitrate | {bitrate:.2f} Mb/s |
53
+ | Extension | {os.path.splitext(audio_file)[1]} |
54
  """
55
 
56
  # Return the PNG file of the spectrogram and the info table
 
59
  # Create the Gradio interface
60
  iface = gr.Interface(fn=create_spectrogram_and_get_info, inputs=gr.Audio(type="filepath"), outputs=["markdown", "image"])
61
  iface.launch()