AI Development

OpenAI Whisper Tutorial: Utilize the Groundbreaking Speech Recognition System

OpenAI Whisper tutorial on speech recognition system implementation.

Introducing Whisper: OpenAI's Groundbreaking Speech Recognition System

Whisper stands tall as OpenAI's cutting-edge speech recognition solution, expertly honed with 680,000 hours of web-sourced multilingual and multitask data. This robust and versatile dataset cultivates exceptional resilience to accents, ambient noise, and technical terminology. Furthermore, it supports seamless transcription in various languages and translation into English. OpenAI graciously unveils models and codes, paving the way for ingenious developers to construct valuable applications that harness the remarkable potential of speech recognition.

How to Use Whisper

The Whisper model is available on GitHub. You can download it with the following command directly in the Jupyter notebook:

!git clone https://github.com/openai/whisper.git

Whisper needs ffmpeg installed on the current machine to work. You might already have it installed, but it's likely your local machine needs this program to be installed first. OpenAI refers to multiple ways to install this package, but we will be using the Scoop package manager. Here is a tutorial on how to do it manually.

In the Jupyter Notebook you can install it with the following command:

scoop install ffmpeg

After the installation, a restart is required if you are using your local machine.

Importing Libraries

Next, we import all necessary libraries:

import whisper
import torch

Using a GPU is the preferred way to use Whisper. If you are using a local machine, you can check if you have a GPU available. The first line results in False if a CUDA-compatible Nvidia GPU is not available and True if it is.

torch.cuda.is_available()

The second line of code sets the model to prefer GPU whenever it is available:

device = "cuda" if torch.cuda.is_available() else "cpu"

Loading the Whisper Model

Now we can load the Whisper model. The model is loaded with the following command:

model = whisper.load_model('base').to(device)

Please keep in mind that there are multiple different models available. You can find all of them on the Whisper GitHub page. Each model has trade-offs between accuracy and speed (compute needed). We will use the 'base' model for this tutorial.

Transcribing Audio Files

Next, you need to load your audio file you want to transcribe:

audio_file = "path/to/your/audiofile.mp3"

The detect_language function detects the language of your audio file:

language, _ = model.detect_language(audio_file)

Decoding Audio

We transcribe the first 30 seconds of the audio using the DecodingOptions and the decode command, then print out the result:

options = whisper.DecodingOptions(language=language)
result = model.decode(audio_file, options)
print(result.text)

Next, we can transcribe the entire audio file:

full_result = model.transcribe(audio_file)
print(full_result['text'])

This will print out the whole audio file transcribed after the execution has finished.

You can find the full code as a Jupyter Notebook here.

How to Leverage This Knowledge?

Now it's up to you to create your own Whisper application. Get creative and have fun! Explore various useful applications for Whisper. The best way is to identify a problem around you and craft a solution to it. Perhaps during our AI Hackathons?

Scopri di più

An overview of AI-based RAG application development using TruLens and Google Cloud.
ChatGPT tutorial for enhancing coding skills with AI support.

Commenta

Nota che i commenti devono essere approvati prima di essere pubblicati.

Questo sito è protetto da hCaptcha e applica le Norme sulla privacy e i Termini di servizio di hCaptcha.