Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import numpy as np
|
4 |
+
import librosa
|
5 |
+
from punctuators.models import PunctCapSegModelONNX
|
6 |
+
|
7 |
+
transcriber = pipeline("automatic-speech-recognition", model="Oysiyl/w2v-bert-2.0-dutch-colab-CV16.0")
|
8 |
+
punct_cap_model = PunctCapSegModelONNX.from_pretrained("1-800-BAD-CODE/xlm-roberta_punctuation_fullstop_truecase")
|
9 |
+
|
10 |
+
def transcribe(audio):
|
11 |
+
sr, y = audio
|
12 |
+
y = y.astype(np.float32)
|
13 |
+
y /= np.max(np.abs(y))
|
14 |
+
if sr != 16000:
|
15 |
+
y = librosa.resample(y, orig_sr=sr, target_sr=16000)
|
16 |
+
transcribed_text = transcriber({"sampling_rate": 16000, "raw": y})["text"]
|
17 |
+
punct_cap_text = punct_cap_model.infer(texts=[transcribed_text], apply_sbd=True)[0][0]
|
18 |
+
return punct_cap_text
|
19 |
+
|
20 |
+
|
21 |
+
demo = gr.Interface(
|
22 |
+
transcribe,
|
23 |
+
gr.Audio(sources=["upload", "microphone"]),
|
24 |
+
outputs="text",
|
25 |
+
title="Automatic Speech Recognition for Dutch language demo",
|
26 |
+
description="Click on the example below, upload audio from file or say something in microphone!",
|
27 |
+
examples=[["examples/example1.wav"], ["examples/example2.wav"]],
|
28 |
+
cache_examples=True
|
29 |
+
)
|
30 |
+
|
31 |
+
demo.launch()
|