Skip to content

Instantly share code, notes, and snippets.

@arturbosch
Last active January 8, 2024 12:17
Show Gist options
  • Save arturbosch/7487408dae66b9343b20740fab7852ec to your computer and use it in GitHub Desktop.
Save arturbosch/7487408dae66b9343b20740fab7852ec to your computer and use it in GitHub Desktop.
whisper speech-to-text
from pathlib import Path
import whisper
# CHANGE THE MODEL HERE: use "base" or "medium"
MODEL_NAME = "base"
MODEL = whisper.load_model(MODEL_NAME)
with open(MODEL_NAME + ".txt", "a", encoding="utf-8") as result_file:
for path in sorted(
Path("wav").glob("*.wav"), key=lambda p: int(p.stem.replace(".wav", ""))
):
print("processing " + str(path) + " ...")
result = MODEL.transcribe(str(path), fp16=False, language="English")
transcript = result["text"].strip()
print(transcript)
result_file.write(transcript)
result_file.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment