How to Develop a Python Application to Amplify and Curtail Audio Signals on Windows 11

Posted by : on

Category : Others

Today, I’m going to share an interesting use case involving Gemini and an AI coding agent (like GPT-5.5) to solve a practical, frustrating problem in my daily life.

The Problem: Windows Volume Limitations

The issue stems from the lack of flexibility in the default Windows audio volume controller. The standard Windows volume slider restricts your range strictly between 0% and 100%. While 0% completely mutes the system, 100% is the hard ceiling for standard audio signal output.

This range is perfectly fine for most media. However, certain YouTube videos, podcasts, or older music tracks are mastered so quietly that they require additional gain beyond 100% just to be clearly audible.

This is a common enough issue that popular media players like VLC have built-in amplification—featuring a volume slider shaped like a right-angled triangle that scales from 0% all the way up to 400%.



However, VLC is only helpful if you are playing a file inside the VLC player itself. The software cannot amplify an audio signal system-wide (for browsers, games, or other apps).

Before the advent of AI coding agents and advanced search tools, my go-to solution was purchasing dedicated Windows 11 volume control software, such as DeskFX Audio Effect Processor. While DeskFX offers an array of complex audio manipulation functions, the only feature I actually needed was simple amplification. Paying an annual subscription fee of roughly $80 USD just for a basic volume boost simply didn’t make economic sense.

The AI Solution

AI models like Gemini and GPT-5.5 are absolute game-changers here. They provided a massive dose of critical technical insights and plenty of architectural suggestions to solve this issue for free.

Following their leads, I researched various tools (like VB-Audio Cable), audio routing theories, and open-source projects (such as WinSoftVol and the python-sounddevice documentation).

From there, I built my own lightweight solution on top of existing open-source libraries.


The Three Core Components

1. The Virtual Cable

The VB-Audio Virtual Cable essentially acts as a digital wire, connecting the Windows system audio output directly to our custom Python application.

An alternative approach would be writing a custom kernel driver (.sys). However, that would require getting the driver digitally signed by Microsoft via the WHQL (Windows Hardware Quality Labs) portal—a massive roadblock for hobbyists who just want a quick, functional solution!

Getting Started: To replicate this project, download the virtual cable application from VB-Audio Cable and follow their standard installation instructions.

2. Python, NumPy, and SoundDevice

  • sounddevice: This module handles the real-time audio streaming, allowing us to pipe the input signal from the virtual cable’s output straight to our physical audio device.
  • numpy: This library gives us a highly efficient way to build a real-time signal meter and construct a fast linear gain amplifier.

Since my primary objective was to alter the audio signal without unnecessary bells and whistles, I wrote this simple callback factory:

from typing import Callable

def make_callback(
    status_reporter: Callable = print,
    signal_observer: Callable | None = None,
    gain: float = 1.0,
) -> Callable:
    """Create the sounddevice callback that applies linear gain to input."""
    
    if gain < 0:
        raise ValueError("Gain must be non-negative")

    def callback(indata, outdata, frames, time, status) -> None:
        if status:
            status_reporter(status)
        if signal_observer is not None:
            signal_observer(indata)
            
        # Apply the multiplication factor to the audio amplitude
        outdata[:] = indata if gain == 1.0 else indata * gain

    return callback

The gain parameter acts as a direct multiplication factor for the audio signal’s amplitude.

Note: While this gain can be set below 1.0 to curtail (attenuate) an overly loud signal, my primary issue was weak audio, so I typically set the gain above 1.0 for amplification.


Installation and Execution

For clean environment management, I use uv to handle package installation and script execution.

  • Run uv sync to install all necessary packages.
  • Run uv run <script_name>.py to execute the application.

Main Application Code

import sys
import numpy as np
import sounddevice as sd

def audio_dsp_callback(indata, outdata, frames, time, status):
    """Processes audio frames in real time using the VLC method."""
    if status:
        print(status, file=sys.stderr)
    
    # 1. VLC Method: Pure linear multiplication. 
    # This preserves 100% of your dynamic range and transients.
    amplified = indata * GAIN_FACTOR
    
    # 2. Hard Truncation: Leave everything below 1.0 completely untouched.
    # Only flat-cut the peaks if they actually hit the ceiling to prevent overflow.
    outdata[:] = np.clip(amplified, -1.0, 1.0)

# Create WASAPI Exclusive settings to minimize latency
wasapi_exclusive = sd.WasapiSettings(exclusive=True)

# Apply settings and open the stream
with sd.Stream(device=(input_device, output_device),
              samplerate=48000,
              blocksize=128,  # Tiny block size for ultra-low latency
              channels=2,
              dtype='float32',
              extra_settings=wasapi_exclusive,  # Bypasses the Windows Mixer
              callback=audio_dsp_callback):
    
    print("Running in ultra-low latency WASAPI Exclusive mode.")

Software Dataflow Diagram

[ Any App: YouTube / VLC / Games ]
               │
               ▼ (Automatically routed via Windows Default Device)
       [ VB-CABLE Input ]
               │
               ▼ (Internal Virtual Wire)
      [ VB-CABLE Output ]
               │
               ▼ (Captured in real-time)
       [ Python Script ]  <─── Applies Amplification & Soft-Limiting (Tanh)
               │
               ▼ (Played back in real-time)
  [ Physical Speakers / DAC ]


Execution Results & Demos

1. Verifying the Signal Stream (Meter Mode)

python cli.py --input-device "CABLE Output" --output-device "Realtek" --hostapi "Windows WASAPI" --meter

Output:

Input: 17: CABLE Output (VB-Audio Virtual Cable) [Windows WASAPI]
Output: 16: Speaker (Realtek(R) Audio) [Windows WASAPI]
################################################################################
Running audio passthrough (shared, 48000 Hz, blocksize=128).
Press Ctrl+C to exit safely.
################################################################################
Signal: silence, peak=0.000000, rms=0.000000, rms_dbfs=-inf, ever_seen=no
Signal: silence, peak=0.000000, rms=0.000000, rms_dbfs=-inf, ever_seen=no
Signal: active,  peak=0.046238, rms=0.025447, rms_dbfs=-31.9, ever_seen=yes
Signal: active,  peak=0.063545, rms=0.033378, rms_dbfs=-29.5, ever_seen=yes
Signal: silence, peak=0.000000, rms=0.000000, rms_dbfs=-inf, ever_seen=yes

The logs confirm that the signal passes through flawlessly, and audio plays in real-time from the physical speakers.

2. Running with 2.5x Amplification

python cli.py --input-device "CABLE Output" --output-device "Realtek" --gain 2.5

Output:

Input: 17: CABLE Output (VB-Audio Virtual Cable) [Windows WASAPI]
Output: 16: Speaker (Realtek(R) Audio) [Windows WASAPI]
################################################################################
Running audio passthrough (shared, 48000 Hz, blocksize=128, gain=2.5).
Press Ctrl+C to exit safely.
################################################################################

Audio passthrough closed safely.


Conclusion

This lightweight Python application provides a seamless way to boost your system audio anywhere from 1.5x to 4x. Best of all, it doesn’t break your default audio ecosystem when turned off. The VB-Audio Virtual Cable is smart enough that when the Python script isn’t running, the audio signal naturally falls back to your computer’s default physical speakers (like Realtek Audio).

Feel free to download, break, and play around with this prototype on GitHub: win_audio Repository.

Happy coding!

About

Hello, My name is Wilson Fok. I love to extract useful insights and knowledge from big data. Constructive feedback and insightful comments are very welcome!