How To Capture and Process Audio Clips with Audacity 3.7 for Raspberry Pi Projects

Overview of the Raspberry Pi Setup

The purpose of this post is to capture and process audio clips for use in any RPI application. While my goal is to generate steam engine sounds for my deadrail engine control project, these steps will apply to any RPI app that needs to generate sound.

Many RPI projects need to play sound files for sound effects, voices, or music. My current project uses a Raspberry Pi Pico, an I2S DAC, and a tiny speaker to generate realistic locomotive sounds. The Pico runs custom classes built with the rpi_app_framework, which handle audio playback, mixing, and sequencing of sound files.

The overall goal is to prepare sound clips (whistle, chuff, hiss, valve pops) that can be triggered and layered by the Pico to simulate a steam locomotive.

Prerequisite: Install Audacity

Before capturing and processing audio, you’ll need Audacity 3.7 installed on your laptop.


Part 1: Capturing Sound Clips from Your Laptop

Audacity 3.7 makes it straightforward to record audio playing on your laptop, such as YouTube videos or streaming music. The cleanest method on Windows 11 is to use Windows WASAPI loopback, which captures the system audio digitally without microphone noise.

Steps to Capture Audio

  • Open Audacity 3.7.
  • Set Audio Host = Windows WASAPI.
  • Set Recording Device = your output device (loopback), e.g., Headphones (loopback) or Speakers (loopback).
  • Press Record in Audacity.
  • Play the audio on your laptop.
  • Stop recording when finished.
  • You now have a digital copy of the audio clip inside Audacity.

Part 2: Processing and Exporting the Clip

Once you’ve captured the sound, you’ll want to prepare it for playback in your Raspberry Pi sound application. The following five steps ensure compatibility and clean audio.

5 Steps for RPi Audio Prep

  1. Trim silence
    Remove leading/trailing silence. Use View → Zoom In and Edit → Find Zero Crossings to cut cleanly.
  2. Normalize volume
    Go to Effect → Normalize. Set peak amplitude to -1.0 dB. This balances levels across clips.
  3. Convert to mono
    Use Tracks → Mix → Mix Stereo Down to Mono. Your RPi app expects single‑channel PCM.
  4. Set sample rates and format
    In Edit → Preferences → Audio Settings:
    • Default Sample Rate = 44100 Hz (ensures new projects start correctly).
    • Project Sample Rate = 44100 Hz (ensures current project exports correctly).
    • Default Sample Format = 16‑bit (matches I2S DAC expectations).
  5. Export as WAV
    Go to File → Export → Export as WAV. Choose WAV (Microsoft) signed 16‑bit PCM, mono, 44100 Hz.

Part 3: Creating a Macro for Automation

To avoid repeating these steps manually for each clip, you can create a Macro in Audacity 3.7.

Steps to Create the Macro

  • Go to Tools → Macros.
  • Click New, name it RPi Sound Prep.
  • Add commands in order:
    1. Truncate Silence
    2. Normalize (Peak amplitude = -1.0 dB)
    3. Mix and Render to Mono
    4. Resample (44100 Hz)
    5. ExportWav (Signed 16‑bit PCM)
  • Save the macro.
  • Run it via Tools → Macros → RPi Sound Prep on any clip.

And Finally…

With this workflow, you can:

  • Capture audio directly from your laptop.
  • Process it into clean, loop‑ready clips.
  • Export files perfectly matched to your Raspberry Pi sound pipeline.
  • Automate the process with a Macro for efficiency.
Total
0
Shares
Related Posts