File size: 763 Bytes
9fd0422
 
 
80b26db
4ca77dc
a439774
 
 
 
 
 
 
80b26db
9fd0422
 
 
 
6fc805b
9fd0422
 
 
 
 
5c2f8ce
6fc805b
9fd0422
 
 
 
 
 
6fc805b
d107a30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr
from transformers import pipeline
import numpy as np

transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-medium")

transcriber.model.config.forced_decoder_ids = (
  transcriber.tokenizer.get_decoder_prompt_ids(
    language="pt", 
    task="transcribe"
  )
)

def transcribe(stream, new_chunk):
    sr, y = new_chunk
    y = y.astype(np.float32)
    y /= np.max(np.abs(y))

    if stream is not None:
        stream = np.concatenate([stream, y])
    else:
        stream = y
    return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]


demo = gr.Interface(
    transcribe,
    ["state", gr.Audio(source="microphone", streaming=True)],
    ["state", "text"],
    live=True,
)

demo.launch(share=True)