Transcribe Audio with SpeechBrain: Run a Pretrained ASR Model
SpeechBrain is a PyTorch toolkit with pretrained speech-recognition models and reproducible training recipes. This guide shows the basic Python workflow for transcribing a short audio file and what to check when choosing a model.
You can transcribe an audio file from Python with a pretrained SpeechBrain ASR model. The example below uses an English Conformer model trained on LibriSpeech, so do not assume it will work equally well for other languages or recording conditions. Check the model card and license for a model that fits your audio.
Set up and run a model
SpeechBrain’s official installation guide recommends installing the PyPI package in an isolated Python environment. Use a separate virtual environment for each project. If you plan to use a GPU, install a CUDA-enabled PyTorch build that matches the official PyTorch instructions for your system.
python -m venv .venv
# macOS/Linux: source .venv/bin/activate
# Windows PowerShell: .venv\\Scripts\\Activate.ps1
python -m pip install --upgrade pip
python -m pip install speechbrainSave this example as transcribe.py. Replace audio.wav with your file path.
from speechbrain.inference import EncoderDecoderASR
asr = EncoderDecoderASR.from_hparams(
source="speechbrain/asr-conformer-transformerlm-librispeech",
savedir="pretrained_models/asr-conformer-transformerlm-librispeech",
)
text = asr.transcribe_file("audio.wav")
print(text)With the virtual environment active, run python transcribe.py. The first run downloads model files, so it needs network access and disk space for the cache. If it succeeds, the recognized sentence appears in the output. This checkpoint is for English speech based on LibriSpeech. APIs can change between SpeechBrain versions; if the code fails, check the documentation for your installed version and the model card for the current import path and call pattern.
What to check when choosing a model
SpeechBrain provides interfaces and models for several tasks, including speech separation and enhancement, speaker recognition, and speech synthesis. The repository’s pretrained-model examples show that each model can have its own task, training data, and inference class. An ASR label alone does not guarantee support for your language or dialect, sample rate, microphone conditions, or long recordings.
Check the model card for:
Whether its supported language and training/evaluation data match your audio
Input requirements such as sample rate, channel count, and file format
Whether the model and data licenses fit your intended use
Whether speed and error rate are acceptable on your device and real recordings
Start with a short, representative recording and compare the output with a human reference transcript. Word error rate (WER) can suit languages evaluated by words; character error rate (CER) may be more appropriate for languages with different word-segmentation conventions. Review names, numbers, technical terms, and negation manually because an aggregate score can miss them.
Inference and training recipes are different
The code above runs inference with a released model. To train a model yourself or reproduce a paper’s experiment, install the repository locally and follow that recipe’s data preparation, extra dependencies, hyperparameter file, and run instructions. The SpeechBrain installation guide says to check each recipe’s extra_requirements.txt and README. Training often needs a GPU, and data access and compute resources must be arranged separately.
If audio cannot be read, check whether the operating system’s required torchaudio audio dependencies are installed, then verify the path, format, and sample rate. If the GPU is not detected, first check whether PyTorch sees a CUDA device. If changing models does not improve recognition, first check whether the input language and domain match the model.
References
[SpeechBrain repository: pretrained models, installation, and inference examples](https://github.com/speechbrain/speechbrain)
[SpeechBrain installation guide: environments, GPU, audio, and recipe dependencies](https://github.com/speechbrain/speechbrain/blob/develop/docs/installation.md)
[Ravanelli et al., Open-Source Conversational AI with SpeechBrain 1.0 (2024)](https://arxiv.org/abs/2407.00463)