Transcription Routing and Audio Clipping with OpenAI Whisper

Lesson 2: Segment-Based Transcription with Whisper API

In the previous lesson, you learned how to load and play audio files using Howler.js in the browser, while controlling playback state from a TypeScript backend. This laid the foundation for interactive audio applications. Now it's time to take the next step: extracting meaningful text from audio using OpenAI Whisper.

But instead of transcribing full audio files, we’ll focus on clipping and transcribing only the audio segments the user listens to—based on when they press start and stop. This will prepare the way for precise, user-driven transcription workflows.


What You’ll Learn

By the end of this lesson, you will be able to:

  • Clip a specific portion of an audio file using ffmpeg.
  • Prepare the clipped audio segment for Whisper transcription.
  • Send a transcription request to the backend with start and duration parameters.
  • Use the OpenAI Whisper API to convert speech to text.

In this lesson, we focus purely on the backend logic. In the upcoming, you’ll learn how the browser tracks segment timing and sends that to the backend.


Prerequisite: Installing ffmpeg

To clip audio files before transcription, we rely on ffmpeg, a powerful command-line tool for processing multimedia files.

While ffmpeg is widely supported, it may not be installed by default on your system. You’ll need to install it manually if you haven’t already.

ffmpeg is a cross-platform utility for handling audio, video, and other media files. In this project, we use it to:

  • Extract a segment of an audio file (-ss and -t)
  • Convert the audio to mono and 16kHz sample rate (as required by Whisper)

Here are common installation methods by platform:

macOS (using Homebrew)

brew install ffmpeg

Ubuntu

sudo apt update
sudo apt install ffmpeg

Windows

To verify installation, run:

ffmpeg -version

You should see version details printed in the terminal.

⚠️ If ffmpeg is not installed or not in your PATH, the clipping step will fail with an error like ffmpeg: command not found.

Backend: Clipping Audio Segments with ffmpeg

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal