Menu

How to add sound effects to a code-rendered video with numpy, and hit -14 LUFS with ffmpeg's two-pass loudnorm
📰

How to add sound effects to a code-rendered video with numpy, and hit -14 LUFS with ffmpeg's two-pass loudnorm

DEV Community: tutorial·Fast Data·about 23 hours ago
#kY5vjEZE
#devtotutorial#devto#dev#sound#freq
Reading 0:00
15s threshold

A silent video loses people. But stock sound effects come with licence terms you have to track, and music libraries are worse. For short data videos we render from code, we synthesise every sound with numpy instead: it takes a few lines per effect, it is ours, and because the animation is code too, every sound can land on the exact frame where something happens.

This post continues the canvas-to-MP4 tutorial : same 4-second bar chart, now with sound, normalised to a loudness that phones and platforms handle well.

Disclosure: I build data tools for AI agents as Fast Data on Apify . This post needs none of them; the script is in our public data-recipes repo .

Three sounds from scratch

Every sound is a short numpy array at 48 kHz. An envelope (fast attack, exponential decay) is what turns a raw sine into something that sounds like an event:

import numpy as np SR = 48_000

def env ( n , attack = 0.003 , decay = 0.2 ) : t = np . arange ( n ) / SR return np . clip ( t / attack , 0 , 1 ) * np .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.