gorkemgoknar commited on
Commit
d64ed9d
·
1 Parent(s): 03058be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -21
app.py CHANGED
@@ -33,25 +33,6 @@ EXAMPLES = [
33
  ["examples/english.wav", "English", True, "Linda", "every window and roof which could command a view of the horrible performance was occupied"],
34
  ]
35
 
36
- def reformat_freq(sr, y):
37
- if sr not in (
38
- 48000,
39
- 16000,
40
- ): # Deepspeech only supports 16k, (we convert 48k -> 16k)
41
- raise ValueError("Unsupported rate", sr)
42
- if sr == 48000:
43
- y = (
44
- ((y / max(np.max(y), 1)) * 32767)
45
- .reshape((-1, 3))
46
- .mean(axis=1)
47
- .astype("int16")
48
- )
49
- sr = 16000
50
- return sr, y
51
-
52
-
53
-
54
-
55
  def stt_record(audio_record_buffer):
56
  #using english model, it is here to reduce memory usage, will trigger download first run
57
  #unfortunately will be slow as it is shared cpu/memory need to free memory after run
@@ -60,9 +41,11 @@ def stt_record(audio_record_buffer):
60
 
61
  if type(audio_record_buffer)!=tuple:
62
  y, sr = librosa.load(audio_record_buffer)
63
- _, y = reformat_freq(sr,y)
64
  else:
65
- _, y = reformat_freq(*audio_record_buffer)
 
 
 
66
  scorer = True # use scorer
67
  if scorer:
68
  acoustic_model.enableExternalScorer(scorer_path)
 
33
  ["examples/english.wav", "English", True, "Linda", "every window and roof which could command a view of the horrible performance was occupied"],
34
  ]
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  def stt_record(audio_record_buffer):
37
  #using english model, it is here to reduce memory usage, will trigger download first run
38
  #unfortunately will be slow as it is shared cpu/memory need to free memory after run
 
41
 
42
  if type(audio_record_buffer)!=tuple:
43
  y, sr = librosa.load(audio_record_buffer)
 
44
  else:
45
+ sr, y = audio_record_buffer
46
+
47
+ y = librosa.resample(y, orig_sr=sr, target_sr=16000)
48
+
49
  scorer = True # use scorer
50
  if scorer:
51
  acoustic_model.enableExternalScorer(scorer_path)