pydub-stubs

0.25.1.6 · active · verified Tue Apr 14

pydub-stubs is a stub-only package providing type information for the pydub library. It aims to enhance type checking and IDE support for pydub, covering its public interface and some private functions. The package is actively maintained, with versions generally aligning with the pydub releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic pydub functionality: loading an audio file, applying a simple effect (volume boost), and exporting the result. It uses a programmatically generated WAV file to ensure the example is runnable without external downloads. For handling common formats like MP3, FLAC, or OGG, ensure `ffmpeg` or `libav` is installed and accessible in your system's PATH.

from pydub import AudioSegment
from pydub.playback import play
import os

# Create a dummy silent WAV file for demonstration
silent_audio = AudioSegment.silent(duration=1000) # 1 second of silence
silent_audio.export("input.wav", format="wav")

# Load an audio file (replace with your actual file if not using dummy)
song = AudioSegment.from_file("input.wav", format="wav")

# Boost volume by 6 dB
louder_song = song + 6

# Export the modified audio
louder_song.export("output.wav", format="wav")

# Play the original and louder song (requires simpleaudio or similar for playback)
# print("Playing original song...")
# play(song)
# print("Playing louder song...")
# play(louder_song)

print("Original and louder audio files created as input.wav and output.wav")
print("Note: For non-WAV formats (like MP3), pydub requires ffmpeg or libav to be installed and in your system PATH.")

# Clean up dummy files
os.remove("input.wav")
os.remove("output.wav")

view raw JSON →