Konstantin Dorichev commited on
Commit
68c743d
·
unverified ·
1 Parent(s): 58bb6e4

Fix file transcribation

Browse files
Files changed (2) hide show
  1. app.py +7 -3
  2. requirements.txt +1 -0
app.py CHANGED
@@ -2,10 +2,12 @@ import gradio as gr
2
  from transformers import pipeline
3
  import numpy as np
4
 
5
- transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
6
 
7
 
8
  def transcribe(stream, new_chunk):
 
 
9
  sr, y = new_chunk
10
 
11
  # Convert to mono if stereo
@@ -19,14 +21,16 @@ def transcribe(stream, new_chunk):
19
  stream = np.concatenate([stream, y])
20
  else:
21
  stream = y
22
- return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
 
 
23
 
24
 
25
  demo = gr.Interface(
26
  transcribe,
27
  ["state", gr.Audio(sources=["upload"], streaming=False)],
28
  ["state", "text"],
29
- live=True,
30
  )
31
 
32
  demo.launch()
 
2
  from transformers import pipeline
3
  import numpy as np
4
 
5
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en", return_timestamps=True)
6
 
7
 
8
  def transcribe(stream, new_chunk):
9
+ # if stream is not None:
10
+ # print(stream.shape, new_chunk)
11
  sr, y = new_chunk
12
 
13
  # Convert to mono if stereo
 
21
  stream = np.concatenate([stream, y])
22
  else:
23
  stream = y
24
+ text = transcriber({"sampling_rate": sr, "raw": stream})["text"]
25
+ # print(text)
26
+ return stream, text
27
 
28
 
29
  demo = gr.Interface(
30
  transcribe,
31
  ["state", gr.Audio(sources=["upload"], streaming=False)],
32
  ["state", "text"],
33
+ # live=True,
34
  )
35
 
36
  demo.launch()
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  transformers
2
  numpy
3
  torch
 
 
1
  transformers
2
  numpy
3
  torch
4
+ torchaudio