voice2VoiceAI / stt.py
sreejang's picture
Create stt.py
f086b42 verified
raw
history blame contribute delete
369 Bytes
# stt.py
from faster_whisper import WhisperModel
# Load model once
stt_model = WhisperModel(
"small",
device="cpu", # change to "cuda" if GPU available
compute_type="int8"
)
def speech_to_text(audio_path):
segments, info = stt_model.transcribe(audio_path)
text = ""
for segment in segments:
text += segment.text
return text