cuticle999 commited on
Commit
47abc89
·
1 Parent(s): ecd37c8

Add application file

Browse files
Files changed (2) hide show
  1. app.py +29 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+
5
+ # transcriber = pipeline("automatic-speech-recognition", model="kotoba-tech/kotoba-whisper-v1.0")
6
+ # transcriber = pipeline("automatic-speech-recognition", model="whisper-large-v3")
7
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-medium")
8
+
9
+ def transcribe(stream, new_chunk):
10
+ sr, y = new_chunk
11
+ y = y.astype(np.float32)
12
+ y /= np.max(np.abs(y))
13
+
14
+ if stream is not None:
15
+ stream = np.concatenate([stream, y])
16
+ else:
17
+ stream = y
18
+ return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
19
+
20
+
21
+ demo = gr.Interface(
22
+ transcribe,
23
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
24
+ ["state", "text"],
25
+ live=True,
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ torchaudio
3
+ transformers