File size: 1,303 Bytes
60b210b
 
f607038
 
 
 
 
60b210b
b1a6a72
08aebc6
f607038
 
 
 
 
 
 
 
54d342c
f607038
 
54d342c
f607038
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
08aebc6
f607038
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os

import gradio as gr
import librosa
import torch
from transformers import WhisperForConditionalGeneration, WhisperProcessor

hf_token = os.getenv("hf_token")

if hf_token is None:
    raise ValueError(
        "Hugging Face token not found. Please set the 'hf_token' environment variable."
    )

processor = WhisperProcessor.from_pretrained(
    "openai/whisper-small",
    language="Indonesian",
    task="transcribe",
    token=hf_token,
)
model = WhisperForConditionalGeneration.from_pretrained(
    "avalonai/whisper-small-jv", token=hf_token
)


def transcribe(audio):
    audio, sampling_rate = librosa.load(audio, sr=16000)
    audio_input = processor(audio, return_tensors="pt", sampling_rate=16000)
    input_values = audio_input.input_features

    with torch.no_grad():
        generated_ids = model.generate(input_values)

    transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)
    return transcription[0]


iface = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(sources="microphone", type="filepath"),
    outputs="text",
    title="Speech-to-text on Javanese Language Demo",
    description="Ini adalah platform untuk pengujian model speech-to-text pada bahasa Jawa oleh Avalon AI. Silahkan coba dengan mengucapkan kalimat",
)

iface.launch()