Backend-Controlled Audio Playback with Howler.js Frontend

Backend-Controlled Audio Playback with Howler.js Frontend

Welcome to the first lesson of our course on audio processing and transcription using Howler.js, TypeScript, and OpenAI Whisper. This lesson lays the groundwork by building a system where users can select an audio file, play it, pause it, or stop it—using backend-controlled logic and frontend audio playback powered by Howler.js.


What is Howler.js, and Why Do We Use It?

Howler.js is a JavaScript audio library that simplifies working with sound in the browser. It supports powerful features like streaming, cross-browser playback, controlling volume, tracking playback position, and more.

Why not use Howler.js on the backend?

The backend doesn’t have access to the browser’s audio system or hardware. It cannot play or pause actual audio because:

  • Node.js runs on the server (not the user’s machine).

  • There is no audio output device available to “play” sound.

  • Instead, the backend only tracks playback intent—like which file the user wants to play—while the frontend (in the browser) uses Howler.js to play the audio.

  • Backend = Playback state manager

  • Frontend = Actual audio player


Project Setup and Dependencies

We’ll use Howler.js in the frontend,. Locally, you can install it using:

yarn add howler

Also make sure that you've installed the required packages for the backend, including TypeScript and Express:

yarn add express
yarn add -D typescript ts-node @types/node @types/express

What You'll Learn

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

  • Serve audio files and playback routes from a TypeScript backend.
  • Use Howler.js to control audio playback in the browser.
  • Sync backend playback state with frontend playback logic.

Backend: Controlling Playback State

We'll use a simple TypeScript module to store which audio file is currently selected.

// src/services/audioController.ts
let currentAudioPath: string | null = null;

export function setCurrentAudio(path: string): void {
  currentAudioPath = path;
}

export function getCurrentAudio(): string | null {
  return currentAudioPath;
}

export function clearCurrentAudio(): void {
  currentAudioPath = null;
}

This file acts like a tiny in-memory database:

  • setCurrentAudio() tells the backend which file is being played.
  • getCurrentAudio() lets us fetch the current selection.
  • clearCurrentAudio() resets everything when audio stops.

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