Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created May 23, 2023 11:53
Show Gist options
  • Select an option

  • Save ehzawad/359e6026081003292e410d36ea1718c4 to your computer and use it in GitHub Desktop.

Select an option

Save ehzawad/359e6026081003292e410d36ea1718c4 to your computer and use it in GitHub Desktop.
from transformers import pipeline
# asr = pipeline("automatic-speech-recognition", model="ehzawad/whisper-tiny-bn")
# output = asr("/root/ehz_asr/sample_bn.mp3", chunk_length_s=600)
# print(output)
# print(type(output))
from datasets import Dataset
from datasets import Audio
audio_dataset = Dataset.from_dict({"audio": ["/root/ehz_asr/sample_bn.mp3"]}).cast_column("audio", Audio())
# ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
sample = audio_dataset[0]["audio"]
print(sample)
print(type(sample))
import torch
from transformers import pipeline
# from datasets import load_dataset
device = "cuda:0" if torch.cuda.is_available() else "cpu"
pipe = pipeline(
"automatic-speech-recognition",
model="ehzawad/whisper-tiny-bn",
chunk_length_s=60000,
device=device,
)
# ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
# sample = ds[0]["audio"]
# sample = "/root/ehz_asr/sample_bn.mp3"
prediction = pipe(sample.copy(), batch_size=256)["text"]
# we can also return timestamps for the predictions
# prediction = pipe(sample.copy(), batch_size=256, return_timestamps=True, max_new_tokens=1000)
prediction = pipe(sample.copy(), batch_size=256, return_timestamps=True, max_new_tokens=1000)["chunks"]
print(prediction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment