Deploying Whisper.cpp on Linux: High-Speed Offline Speech-to-Text Without a GPU

Artificial Intelligence tutorial - IT technology blog
Artificial Intelligence tutorial - IT technology blog

At 2:14 AM, my phone wouldn’t stop buzzing with alerts from our monitoring system. The Speech-to-Text worker on our production Linux server had just crashed hard. After SSHing in and running dmesg -T | grep -i oom, I saw that the Linux kernel had ruthlessly OOM-killed the Python process running the original Whisper model.

This VPS only had 4 vCPUs, 8GB of RAM, and no GPU. Meanwhile, customers were still pushing call recordings onto the queue every single minute. I had to overhaul the processing architecture right then and there in the middle of the night to bring the system back to life.

4 Ways to Handle Speech-to-Text on CPU-Only Linux

To transcribe audio automatically on a CPU-only server, you generally have 4 main options:

  • OpenAI Whisper API (Cloud): Send audio files directly over HTTPS to OpenAI’s servers and get JSON back.
  • openai-whisper library (Python + PyTorch CPU): Install OpenAI’s official Python package and force PyTorch to run on the CPU.
  • faster-whisper (CTranslate2): A reimplementation using the CTranslate2 engine to optimize inference speed on both CPU and GPU.
  • whisper.cpp (Pure C/C++): A dependency-free C/C++ port of the Whisper model supporting quantization and SIMD instruction sets like AVX2.

Pros and Cons of Each Approach Under Production Load

At 2 AM, every decision boils down to RAM, CPU, and stability. Looking back through the logs and running quick benchmarks for each solution, here is what I observed in practice.

1. OpenAI Whisper API

Pros: Zero compute load on your server. High accuracy, and the integration takes just a few lines of API calls.

Cons: File uploads are capped at 25MB. During traffic spikes, it’s easy to hit 429 Rate Limit errors or timeouts. More importantly, internal call recordings have to leave your network over the internet, making it hard to pass security audits. Costs also add up fast: at $0.006/minute, 10,000 minutes of audio per month already runs $60.

2. Python + PyTorch CPU (openai-whisper)

Pros: Familiar installation via pip with all original features intact.

Cons: This was the exact culprit behind our midnight outage. PyTorch on CPU is bulky. Just loading the small or medium model eats anywhere from 2.5GB to over 6GB of RAM. A 5-minute audio clip can take ten minutes or more to process. Just 2–3 concurrent requests will max out memory, and the OOM killer immediately steps in.

3. Faster-whisper

Pros: 2x to 4x faster than the original PyTorch implementation. Supports int8 quantization, bringing RAM usage for the small model down to around 1–1.5GB.

Cons: You still have to maintain a Python environment, virtualenv, and CTranslate2 dependencies. On older Linux distributions, system library version conflicts like glibc still pop up occasionally.

4. Whisper.cpp

Pros: Compiles down to a single C++ binary—no Python or CUDA required. Thanks to quantized GGML models, the small model only consumes about 450MB–1.2GB of RAM depending on the quantization level. The binary runs multi-threaded and takes full advantage of AVX2/FMA instructions, delivering very consistent throughput.

Cons: You have to compile it from source yourself. Input files must also be 16kHz mono WAV, meaning you need ffmpeg to convert them beforehand.

Why Whisper.cpp Wins on a CPU-Only Server

With 4 vCPUs, 8GB of RAM, and a requirement for offline processing to keep data internal, Whisper.cpp targets the exact bottleneck. Running a standalone C++ executable decouples the AI workload from the main web application. As a result, memory usage becomes far more predictable, and you never have to worry about Python package conflicts again.

In production, performance has been rock-solid. RAM holds steady at around 450MB per worker using the small-q5_1 model. Transcription speed for both Vietnamese and English averages about 0.3x–0.5x real-time: a 10-minute audio file takes roughly 3–4 minutes to process on a standard CPU.

Step-by-Step: Deploying Whisper.cpp on Linux

Here are the exact steps I ran on Ubuntu 22.04 LTS to get the service back online before sunrise.

Step 1: Check CPU Flags and Install Build Tools

First, verify that your CPU supports the avx2 instruction set to ensure good compute performance. Then install build-essential, cmake, and ffmpeg:

lscpu | grep -o 'avx2'
sudo apt update && sudo apt install -y git build-essential cmake ffmpeg

Step 2: Clone the Repository and Build

Clone the official repository into /opt and build it in Release mode using CMake:

cd /opt
sudo git clone https://github.com/ggml-org/whisper.cpp.git
cd whisper.cpp
sudo cmake -B build -DCMAKE_BUILD_TYPE=Release
sudo cmake --build build -j$(nproc)

Once compiled, the main binary will be located at /opt/whisper.cpp/build/bin/whisper-cli.

Step 3: Download the Model and Apply Quantization

On a CPU, don’t bother trying to run the large model—the wait times will be brutal. For conversational Vietnamese and English, the small model or its quantized small-q5_1 variant strikes a great balance between speed and accuracy:

# Download the standard small model (~488MB)
bash ./models/download-ggml-model.sh small

# Quantize to q5_1 (~190MB) to save even more RAM
./build/bin/quantize models/ggml-small.bin models/ggml-small-q5_1.bin q5_1

Step 4: Normalize Audio Files and Run a Test

Whisper.cpp only accepts 16kHz, 1-channel (mono), 16-bit PCM WAV files. Passing an MP3 or M4A directly will fail immediately. Use ffmpeg to convert the audio first:

ffmpeg -y -i call_recording.mp3 -ar 16000 -ac 1 -c:a pcm_s16le audio_16k.wav

/opt/whisper.cpp/build/bin/whisper-cli \
  -m /opt/whisper.cpp/models/ggml-small-q5_1.bin \
  -f audio_16k.wav \
  -t 4 \
  -l vi \
  --output-txt

Key flags explained:

  • -t 4: Number of CPU threads to use. Match this to your physical cores or vCPUs; setting it too high causes context-switching overhead that slows things down.
  • -l vi: Force Vietnamese language detection to skip auto-detection, saving a few seconds at startup and improving accuracy.
  • --output-txt: Writes the transcript to audio_16k.wav.txt so it’s easy to read or save to a database.

Step 5: Call Whisper.cpp from a Python Backend

To replace the old worker without tearing down your existing queue system, simply invoke the whisper-cli binary using subprocess. Make sure to clean up temporary files in a finally block so you don’t fill up the disk:

import subprocess
import os

def transcribe_audio(input_path: str, lang: str = "vi") -> str:
    wav_path = f"{input_path}.16k.wav"
    txt_path = f"{wav_path}.txt"
    model_path = "/opt/whisper.cpp/models/ggml-small-q5_1.bin"
    bin_path = "/opt/whisper.cpp/build/bin/whisper-cli"

    try:
        # 1. Convert to 16kHz mono WAV
        subprocess.run(
            ["ffmpeg", "-y", "-i", input_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", wav_path],
            check=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
        )

        # 2. Run whisper.cpp
        subprocess.run(
            [bin_path, "-m", model_path, "-f", wav_path, "-t", "4", "-l", lang, "--output-txt"],
            check=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.PIPE,
        )

        with open(txt_path, "r", encoding="utf-8") as f:
            return f.read().strip()
    finally:
        for tmp in (wav_path, txt_path):
            if os.path.exists(tmp):
                os.remove(tmp)

One quick production tip: if you use Celery to run multiple workers in parallel, divide the thread count accordingly. For instance, on a 4-vCPU server, you can set --concurrency=2 and pass -t 2 to each process to avoid CPU contention. With a lean setup like this, a GPU-less VPS can easily handle 24/7 Speech-to-Text workloads with zero midnight OOM alerts.

Share: