arampacha commited on
Commit
868269b
1 Parent(s): dd835e9
Files changed (4) hide show
  1. README.md +3 -3
  2. app.py +41 -0
  3. packages.txt +1 -0
  4. requirements.txt +6 -0
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Asr Ukrainian
3
- emoji:
4
- colorFrom: red
5
  colorTo: yellow
6
  sdk: gradio
7
  app_file: app.py
 
1
  ---
2
+ title: ASR Ukrainian
3
+ emoji: 💬
4
+ colorFrom: blue
5
  colorTo: yellow
6
  sdk: gradio
7
  app_file: app.py
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline, Wav2Vec2ProcessorWithLM
2
+ from librosa import to_mono, resample
3
+ import numpy as np
4
+ import gradio as gr
5
+
6
+ model_id = "arampacha/wav2vec2-xls-r-1b-uk"
7
+
8
+ processor = Wav2Vec2ProcessorWithLM.from_pretrained(model_id)
9
+
10
+ asr = pipeline(
11
+ "automatic-speech-recognition", model=model_id, device=-1,
12
+ feature_extractor=processor.feature_extractor, decoder=processor.decoder
13
+ )
14
+ def run_asr(audio):
15
+ sr, audio_array = audio
16
+ audio_array = audio_array.astype(np.float32)
17
+ if len(audio_array.shape) > 1:
18
+ if audio_array.shape[1] == 1:
19
+ audio_array = audio_array.squeeze()
20
+ elif audio_array.shape[1] == 2:
21
+ audio_array = to_mono(audio_array.T)
22
+ else:
23
+ raise ValueError("Audio with > 2 channels not supported")
24
+ if sr != 16_000:
25
+ audio_array = resample(audio_array, orig_sr=sr, target_sr=16_000)
26
+ res = asr(audio_array, chunk_length_s=20, stride_length_s=2)
27
+
28
+ return res["text"]
29
+
30
+ text_out = gr.outputs.Textbox(label="transcript")
31
+ interface = gr.Interface(
32
+ run_asr,
33
+ "microphone",
34
+ text_out,
35
+ layout="horizontal",
36
+ theme="huggingface",
37
+ title="Speech-to-text Ukrainian",
38
+ flagging_options=["incorrect"]
39
+ )
40
+
41
+ interface.launch()
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ libsndfile1
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ -f https://download.pytorch.org/whl/cpu/torch_stable.html
2
+ torch==1.10.2+cpu
3
+ librosa
4
+ transformers
5
+ pypi-kenlm
6
+ pyctcdecode