DEV Community

Cover image for Transcribing Turkish with Whisper: Local Audio‑Text Pipeline
Mustafa ERBAY
Mustafa ERBAY

Posted on • Originally published at mustafaerbay.com.tr

Transcribing Turkish with Whisper: Local Audio‑Text Pipeline

Whisper model and Turkish support

The Whisper model is an open‑source, multilingual speech‑to‑text system released by OpenAI in September 2022. Because it supports 99 languages, it can be used out of the box without any language‑specific fine‑tuning, and it includes Turkish. The large variant has 1.55 billion parameters.

Whisper’s architecture uses an encoder‑decoder Transformer. This design provides robustness to various accents and background noise, allowing it to turn recordings from low‑quality microphones into meaningful text. The training dataset consists of 680 k hours of multilingual, multitask supervised audio collected from the web.

ℹ️ Audio quality

The model performs best with mono audio files sampled at 16 kHz. Lower sampling rates or stereo audio can affect transcription accuracy.

Environment setup and dependency management

To use Whisper you need Python 3.8–3.11 and the pip package manager. First make sure the ffmpeg tool is installed on your system, as Whisper relies on ffmpeg for audio preprocessing.

# Ubuntu or Debian based systems
sudo apt update && sudo apt install ffmpeg
# macOS (Homebrew)
brew install ffmpeg
# Windows (Chocolatey)
choco install ffmpeg
Enter fullscreen mode Exit fullscreen mode

Then install the Whisper package with pip:

pip install -U openai-whisper
Enter fullscreen mode Exit fullscreen mode

If you have a CUDA‑capable GPU, installing a compatible PyTorch build for GPU‑accelerated inference is recommended. For example, for CUDA 11.8 you can use the following command:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Enter fullscreen mode Exit fullscreen mode

If no GPU is available, use the following command to install a CPU‑optimized PyTorch build:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
Enter fullscreen mode Exit fullscreen mode

A virtual environment (venv) provides an isolated Python environment; creating one with python -m venv .venv && source .venv/bin/activate runs independently of system packages and prevents dependency conflicts.

Preparing audio files and preprocessing

Although Whisper supports many audio formats, it is recommended that files be in WAV or FLAC format with a 16 kHz sampling rate and a single channel (mono). You can perform this conversion with ffmpeg:

ffmpeg -i input.mp3 -ar 16000 -ac 1 output.wav
Enter fullscreen mode Exit fullscreen mode

Normalizing the volume of recordings captured in noisy environments can be done as an optional preprocessing step with external tools like sox. For example, the command sox output.wav normalized.wav gain -n can normalize the average RMS level. This helps reduce the risk of the model missing words in low‑volume sections.

Whisper processes audio internally in 30‑second chunks. For very long files (e.g., several hours) or systems with limited memory, splitting the file into smaller segments can help manage memory usage. For instance, you can split a file into 10‑minute pieces using ffmpeg:

ffmpeg -i normalized.wav -f segment -segment_time 600 -c copy part_%03d.wav
Enter fullscreen mode Exit fullscreen mode

Transcription steps with Python

import whisper
import pathlib

# Load the large model variant.
# Model weights are typically downloaded to ~/.cache/whisper.
model = whisper.load_model("large")
audio_path = pathlib.Path("part_000.wav")    # A pre‑processed chunk
result = model.transcribe(str(audio_path), language="tr")
print(result["text"])
Enter fullscreen mode Exit fullscreen mode

The snippet above shows that load_model downloads the model weights, and the transcribe method, with language="tr" specified, disables automatic language detection and locks it to Turkish. The result dictionary contains the raw transcript under the text key and timestamps in the segments list.

Each entry in the segments list is structured like {"id":0, "seek":0, "start":0.0, "end":5.12, "text":"Hello world", "tokens":[...]}, providing a clear view of which words were spoken during a specific time interval.

# Combine multiple segments from a single file
full_text = " ".join([s["text"] for s in result["segments"]])
print(full_text)
Enter fullscreen mode Exit fullscreen mode

Creating a loop for multiple audio parts can be done easily with for part in pathlib.Path('.').glob('part_*.wav'):; this aggregates a large collection of audio files into a single transcript.

Post‑processing: text cleaning and timestamps

The transcription output usually includes punctuation and case conversion, but additional text cleaning and formatting can improve the end‑user experience. For example, you can replace double spaces with a single space and capitalize the first character of a sentence using: result["text"].replace(" ", " ").strip().capitalize().

Timestamps are available as start and end fields in result["segments"]. Converting them to SRT format can be done with a simple loop using the srt library:

from pathlib import Path
import srt

def to_srt(segments):
    entries = []
    for i, seg in enumerate(segments, 1):
        entry = srt.Subtitle(index=i,
                             start=srt.timedelta(seconds=seg["start"]),
                             end=srt.timedelta(seconds=seg["end"]),
                             content=seg["text"].strip())
        entries.append(entry)
    return srt.compose(entries)

srt_content = to_srt(result["segments"])
Path("output.srt").write_text(srt_content, encoding="utf-8")
Enter fullscreen mode Exit fullscreen mode

This code saves each segment as a subtitle line, enabling media players to synchronize it directly.

Performance monitoring and debugging

torch.cuda.is_available() checks whether a GPU is present. If it returns True, you can create a GPU‑enabled model with model = whisper.load_model("large", device="cuda"). When no GPU is available, the device="cpu" option automatically runs a CPU‑optimized execution.

To measure processing time you can use the time module: start = time.time(); model.transcribe(...); elapsed = time.time() - start. This quantifies performance differences across audio lengths and model variants.

⚠️ Memory constraints

In a CPU‑only environment the large model can consume a substantial amount of RAM (roughly 3.9 GB up to 10 GB). If memory is insufficient, you may need to switch to smaller model variants such as medium or small to avoid out‑of‑memory errors.

Pipeline visualization

Diagram

This diagram shows the flow from an audio file to the final text as a single‑direction pipeline; each box takes the output of the previous step and feeds it into the next.

Conclusion

Processing Turkish audio files with Whisper locally makes it possible to generate high‑accuracy transcripts when proper preprocessing and model selection are applied. Clear command and configuration examples at each pipeline stage create a reusable template and enable rapid integration into production environments.

The next step is to add this pipeline to a CI/CD workflow to provide an automated transcription service; an example GitHub Actions file runs the whisper command inside a Docker container, offering a scalable solution.

Official Resources

Top comments (0)