Skip to content

Instantly share code, notes, and snippets.

@jeanmidevacc
Created January 28, 2024 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeanmidevacc/9a745e81dd7cd8cee7c3f6c01139025a to your computer and use it in GitHub Desktop.
Save jeanmidevacc/9a745e81dd7cd8cee7c3f6c01139025a to your computer and use it in GitHub Desktop.
local_hf_whisper
import torch
from transformers import pipeline
device = "cuda:0" if torch.cuda.is_available() else "cpu"
mapping = {"whisper-tiny" : "tiny", "whisper-small" : "small", "whisper-medium" : "medium", "whisper-base" : "base"}
hf_model_name = "whisper-medium"
size_model = mapping[hf_model_name] #tiny, base, small, medium
model = pipeline(
"automatic-speech-recognition",
model=f"openai/{hf_model_name}",
chunk_length_s=30,
device=device,
)
def get_transcript_local_whisper_hf(model, file, language="french"):
return model(file, generate_kwargs={"language": language})["text"]
transcript = get_transcript_local_whisper_hf(model, file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment