hagenw commited on
Commit
4923d25
1 Parent(s): 416b735

Add resampling

Browse files
Files changed (2) hide show
  1. app.py +4 -1
  2. requirements.txt +1 -0
app.py CHANGED
@@ -8,6 +8,7 @@ from transformers.models.wav2vec2.modeling_wav2vec2 import Wav2Vec2Model
8
  from transformers.models.wav2vec2.modeling_wav2vec2 import Wav2Vec2PreTrainedModel
9
 
10
  import audiofile
 
11
 
12
 
13
  model_name = "audeering/wav2vec2-large-robust-24-ft-age-gender"
@@ -109,7 +110,9 @@ def recognize(file):
109
  "before submitting your request."
110
  )
111
  signal, sampling_rate = audiofile.read(file, duration=duration)
112
- age_gender = process_func(signal, sampling_rate)
 
 
113
  age = f"{round(age_gender['age'])} years"
114
  gender = {k: v for k, v in age_gender.items() if k != "age"}
115
  return age, gender
 
8
  from transformers.models.wav2vec2.modeling_wav2vec2 import Wav2Vec2PreTrainedModel
9
 
10
  import audiofile
11
+ import audresample
12
 
13
 
14
  model_name = "audeering/wav2vec2-large-robust-24-ft-age-gender"
 
110
  "before submitting your request."
111
  )
112
  signal, sampling_rate = audiofile.read(file, duration=duration)
113
+ target_rate = 16000
114
+ signal = audresample.resample(signal, sampling_rate, target_rate)
115
+ age_gender = process_func(signal, target_rate)
116
  age = f"{round(age_gender['age'])} years"
117
  gender = {k: v for k, v in age_gender.items() if k != "age"}
118
  return age, gender
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  audiofile
 
2
  torch
3
  transformers
 
1
  audiofile
2
+ audresample
3
  torch
4
  transformers