Enutrof commited on
Commit
3551f33
·
1 Parent(s): 9cc6970

Updated files to process audio properly.

Browse files
Files changed (2) hide show
  1. app.py +3 -1
  2. inference.py +4 -3
app.py CHANGED
@@ -4,5 +4,7 @@ from inference import *
4
  def greet(name):
5
  return "Hello " + name + "!"
6
 
7
- iface = gr.Interface(fn=inference, inputs="audio", outputs="text")
 
 
8
  iface.launch()
 
4
  def greet(name):
5
  return "Hello " + name + "!"
6
 
7
+ iface = gr.Interface(fn=inference,
8
+ inputs=gr.inputs.Audio(source="upload", type="filepath"),
9
+ outputs="text")
10
  iface.launch()
inference.py CHANGED
@@ -11,7 +11,6 @@ def extract_mfcc_batch(file_path, n_mfcc=13, n_fft=1024, hop_length=512, length_
11
  """
12
  mfcc_batch = []
13
  num_samples_per_segment = 220500 #length_segment * SAMPLE_RATE
14
- expected_num_mfcc_vectors_per_segment = math.ceil(num_samples_per_segment / hop_length)
15
 
16
  signal, sr = librosa.load(file_path, sr=SAMPLE_RATE)
17
 
@@ -22,7 +21,7 @@ def extract_mfcc_batch(file_path, n_mfcc=13, n_fft=1024, hop_length=512, length_
22
  start_sample = num_samples_per_segment * s
23
  finish_sample = start_sample + num_samples_per_segment
24
  try:
25
- mfcc = librosa.feature.mfcc(signal[start_sample:finish_sample],
26
  sr=SAMPLE_RATE,
27
  n_fft=n_fft,
28
  n_mfcc=n_mfcc,
@@ -33,7 +32,9 @@ def extract_mfcc_batch(file_path, n_mfcc=13, n_fft=1024, hop_length=512, length_
33
  # store mfcc for segment if it has the expected length
34
  if len(mfcc) == 431:
35
  mfcc_batch.append(mfcc.tolist())
36
- except:
 
 
37
  continue
38
  return mfcc_batch
39
 
 
11
  """
12
  mfcc_batch = []
13
  num_samples_per_segment = 220500 #length_segment * SAMPLE_RATE
 
14
 
15
  signal, sr = librosa.load(file_path, sr=SAMPLE_RATE)
16
 
 
21
  start_sample = num_samples_per_segment * s
22
  finish_sample = start_sample + num_samples_per_segment
23
  try:
24
+ mfcc = librosa.feature.mfcc(y=signal[start_sample:finish_sample],
25
  sr=SAMPLE_RATE,
26
  n_fft=n_fft,
27
  n_mfcc=n_mfcc,
 
32
  # store mfcc for segment if it has the expected length
33
  if len(mfcc) == 431:
34
  mfcc_batch.append(mfcc.tolist())
35
+
36
+ except Exception as e:
37
+ print(e)
38
  continue
39
  return mfcc_batch
40