Korean automatic speech recognition model exported to ONNX for fast inference.
import numpy as np
import soundfile as sf
from optimum.onnxruntime import ORTModelForSpeechSeq2Seq
from transformers import WhisperProcessor
model_id = "YOUR_USERNAME/whisper-small-ko-new-onnx"
processor = WhisperProcessor.from_pretrained(model_id)
model = ORTModelForSpeechSeq2Seq.from_pretrained(model_id)
# Load 16kHz mono audio
audio, sr = sf.read("sample.wav")
if sr != 16000:
raise ValueError("Please provide 16kHz audio.")
if audio.ndim > 1:
audio = np.mean(audio, axis=1)
inputs = processor(audio, sampling_rate=16000, return_tensors="pt")
predicted_ids = model.generate(inputs.input_features)
text = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
print(text)