Created
January 28, 2024 18:16
-
-
Save jeanmidevacc/9a745e81dd7cd8cee7c3f6c01139025a to your computer and use it in GitHub Desktop.
local_hf_whisper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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