Transformers - Example of automatic speech recognition¶
Transformers provides APIs and tools to easily download and train state-of-the-art pretrained models.
Credits: Huggingface documentation and examples
In [1]:
from transformers import pipeline
In [2]:
# Create the transcriber pipeline with GPU
transcriber = pipeline(task="automatic-speech-recognition", model="openai/whisper-small", device=0) # Specify the GPU device index)
In [3]:
speech_url="https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac"
In [4]:
# Play th eaudio file
import IPython
IPython.display.Audio(url=speech_url)
Out[4]:
In [ ]:
# Install ffmpeg
In [ ]:
%%bash
wget -O ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz
tar xvf ffmpeg.tar.xz
In [5]:
import os
path = os.environ['PATH']
os.environ['PATH'] += ":./ffmpeg-git-20230313-amd64-static" # customize the folder name
In [6]:
# transcribe from speech_url
transcriber(speech_url)
Out[6]:
In [ ]: