TheStinger commited on
Commit
420adc3
·
1 Parent(s): 073f5be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -6,7 +6,7 @@ import soundfile as sf
6
 
7
  def create_spectrogram_and_get_info(audio_file):
8
  # Read the audio data from the file
9
- audio_data, sample_rate = sf.read(audio_file)
10
 
11
  # Flatten the audio data if it's not mono
12
  if len(audio_data.shape) > 1:
@@ -19,7 +19,7 @@ def create_spectrogram_and_get_info(audio_file):
19
  plt.savefig('spectrogram.png')
20
 
21
  # Get the audio file info
22
- audio_info = sf.info(audio_file)
23
 
24
  # Create a table with the audio file info
25
  info_table = f"""
@@ -29,14 +29,14 @@ def create_spectrogram_and_get_info(audio_file):
29
  | Campioni al secondo | {audio_info.samplerate} Hz |
30
  | Canali | {audio_info.channels} |
31
  | Bitrate | {audio_info.samplerate * audio_info.channels * audio_info.subtype.itemsize * 8} bit/s |
32
- | Estensione | {os.path.splitext(audio_file)[1]} |
33
  """
34
 
35
  # Return the PNG file of the spectrogram and the info table
36
  return info_table, 'spectrogram.png'
37
 
38
  # Create the Gradio interface
39
- iface = gr.Interface(fn=create_spectrogram_and_get_info, inputs=gr.Audio(type="filepath"), outputs=["markdown", "image"])
40
  iface.launch()
41
 
42
 
 
6
 
7
  def create_spectrogram_and_get_info(audio_file):
8
  # Read the audio data from the file
9
+ audio_data, sample_rate = sf.read(audio_file.name)
10
 
11
  # Flatten the audio data if it's not mono
12
  if len(audio_data.shape) > 1:
 
19
  plt.savefig('spectrogram.png')
20
 
21
  # Get the audio file info
22
+ audio_info = sf.info(audio_file.name)
23
 
24
  # Create a table with the audio file info
25
  info_table = f"""
 
29
  | Campioni al secondo | {audio_info.samplerate} Hz |
30
  | Canali | {audio_info.channels} |
31
  | Bitrate | {audio_info.samplerate * audio_info.channels * audio_info.subtype.itemsize * 8} bit/s |
32
+ | Estensione | {os.path.splitext(audio_file.name)[1]} |
33
  """
34
 
35
  # Return the PNG file of the spectrogram and the info table
36
  return info_table, 'spectrogram.png'
37
 
38
  # Create the Gradio interface
39
+ iface = gr.Interface(fn=create_spectrogram_and_get_info, inputs=gr.Audio(type="numpy"), outputs=["markdown", "image"])
40
  iface.launch()
41
 
42