my-gradio-app / utils /speech_recognition.py
Nguyen Trong Lap
Recreate history without binary blobs
eeb0f9c
raw
history blame contribute delete
574 Bytes
"""
Speech-to-Text Module
Handles audio recording and speech recognition using Hugging Face
"""
import logging
from transformers import pipeline
logger = logging.getLogger(__name__)
model_id = "vinai/PhoWhisper-base"
pipe = pipeline("automatic-speech-recognition", model=model_id)
def transcribe_speech(filepath):
output = pipe(
filepath,
max_new_tokens=256,
generate_kwargs={
"task": "transcribe",
"language": "vietnamese",
},
chunk_length_s=30,
batch_size=8,
)
return output["text"]