Spaces:
Running
Running
mutisya
commited on
Commit
•
6becda8
0
Parent(s):
Duplicate from mutisya/kik_asr_demo_1
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +72 -0
- packages.txt +3 -0
- requirements.txt +11 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Kikuyu Asr Demo 1
|
3 |
+
emoji: 🌖
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.19.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: mutisya/kik_asr_demo_1
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from pydub import AudioSegment
|
4 |
+
import pyaudioconvert as pac
|
5 |
+
import torch
|
6 |
+
import torchaudio
|
7 |
+
import sox
|
8 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor,Wav2Vec2ProcessorWithLM
|
9 |
+
|
10 |
+
|
11 |
+
def convert (audio):
|
12 |
+
file_name = audio
|
13 |
+
if file_name.endswith("mp3") or file_name.endswith("wav") or file_name.endswith("ogg"):
|
14 |
+
if file_name.endswith("mp3"):
|
15 |
+
sound = AudioSegment.from_mp3(file_name)
|
16 |
+
sound.export(audio, format="wav")
|
17 |
+
elif file_name.endswith("ogg"):
|
18 |
+
sound = AudioSegment.from_ogg(audio)
|
19 |
+
sound.export(audio, format="wav")
|
20 |
+
else:
|
21 |
+
return False
|
22 |
+
pac.convert_wav_to_16bit_mono(audio,audio)
|
23 |
+
return True
|
24 |
+
|
25 |
+
|
26 |
+
def parse_transcription_with_lm(logits):
|
27 |
+
result = processor_with_LM.batch_decode(logits.cpu().numpy())
|
28 |
+
text = result.text
|
29 |
+
transcription = text[0].replace('<s>','')
|
30 |
+
return transcription
|
31 |
+
|
32 |
+
def parse_transcription(logits):
|
33 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
34 |
+
transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
|
35 |
+
return transcription
|
36 |
+
|
37 |
+
def transcribe(audio, audio_microphone, applyLM):
|
38 |
+
audio_path = audio_microphone if audio_microphone else audio
|
39 |
+
speech_array, sampling_rate = torchaudio.load(audio_path)
|
40 |
+
speech = torchaudio.functional.resample(speech_array, orig_freq=sampling_rate, new_freq=16000).squeeze().numpy()
|
41 |
+
"""
|
42 |
+
if convert(audio_path)== False:
|
43 |
+
return "The format must be mp3,wav and ogg"
|
44 |
+
speech, sample_rate = torchaudio.load(audio_path)
|
45 |
+
"""
|
46 |
+
|
47 |
+
inputs = processor(speech, sampling_rate=16_000, return_tensors="pt", padding=True)
|
48 |
+
with torch.no_grad():
|
49 |
+
logits = model(inputs.input_values).logits
|
50 |
+
|
51 |
+
if applyLM:
|
52 |
+
return parse_transcription_with_lm(logits)
|
53 |
+
else:
|
54 |
+
return parse_transcription(logits)
|
55 |
+
|
56 |
+
auth_token = os.environ.get("key") or True
|
57 |
+
model_id = "mutisya/wav2vec2-300m-kik-t22-1k-ft-withLM"
|
58 |
+
processor = Wav2Vec2Processor.from_pretrained(model_id, use_auth_token=auth_token)
|
59 |
+
processor_with_LM = Wav2Vec2ProcessorWithLM.from_pretrained(model_id, use_auth_token=auth_token)
|
60 |
+
model = Wav2Vec2ForCTC.from_pretrained(model_id, use_auth_token=auth_token)
|
61 |
+
|
62 |
+
|
63 |
+
gradio_ui = gr.Interface(
|
64 |
+
fn=transcribe,
|
65 |
+
title="Kikuyu Speech Recognition",
|
66 |
+
description="",
|
67 |
+
inputs=[gr.Audio(label="Upload Audio File", type="filepath", optional=True),
|
68 |
+
gr.Audio(source="microphone", type="filepath", optional=True, label="Record from microphone"),
|
69 |
+
gr.Checkbox(label="Apply LM", value=False)],
|
70 |
+
outputs=[gr.outputs.Textbox(label="Recognized speech")]
|
71 |
+
)
|
72 |
+
gradio_ui.launch(enable_queue=True)
|
packages.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
libsndfile1
|
2 |
+
sox
|
3 |
+
ffmpeg
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
https://github.com/kpu/kenlm/archive/master.zip
|
3 |
+
pyctcdecode
|
4 |
+
soundfile
|
5 |
+
torch
|
6 |
+
torchaudio
|
7 |
+
transformers
|
8 |
+
pydub
|
9 |
+
pyaudioconvert
|
10 |
+
sox
|
11 |
+
scipy
|