Enric Perpinyà Pitarch commited on
Commit
34afb82
1 Parent(s): 4af0e95

Offline check

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