{"library":"pydub","code":"from pydub import AudioSegment\n\n# Create a dummy audio file for the example (replace with your actual file)\n# This part requires ffmpeg if you want to export to mp3/other formats.\n# For pure WAV, pydub can handle it natively.\ntry:\n    # Attempt to create a simple silent WAV file if no external file exists\n    one_second_of_silence = AudioSegment.silent(duration=1000)\n    one_second_of_silence.export(\"input.wav\", format=\"wav\")\n    print(\"Created a dummy 'input.wav' file.\")\nexcept Exception as e:\n    print(f\"Could not create dummy WAV: {e}. Please provide an existing audio file or ensure ffmpeg is installed for non-WAV formats.\")\n\n# --- Pydub operations ---\n\n# Load an audio file (e.g., input.wav or input.mp3)\n# If you use .mp3, make sure ffmpeg is installed and in your PATH.\ntry:\n    song = AudioSegment.from_file(\"input.wav\", format=\"wav\")\n    print(f\"Loaded audio segment. Duration: {len(song) / 1000.0} seconds.\")\n\n    # Increase volume by 6 dB\n    louder_song = song + 6\n\n    # Add a 2-second fade in and 3-second fade out\n    faded_song = louder_song.fade_in(2000).fade_out(3000)\n\n    # Export the manipulated audio to a new file\n    output_filename = \"output.mp3\"\n    faded_song.export(output_filename, format=\"mp3\")\n    print(f\"Exported '{output_filename}' successfully.\")\n\n    # To play the audio (requires simpleaudio or pyaudio, and ffplay/avplay if not using WAV)\n    # from pydub.playback import play\n    # play(faded_song)\n\nexcept FileNotFoundError:\n    print(\"Error: input.wav not found. Please create one or provide an existing audio file.\")\nexcept Exception as e:\n    print(f\"An error occurred during audio processing: {e}. Check FFmpeg installation if using non-WAV files.\")\n","lang":"python","description":"This quickstart demonstrates how to load an audio file, apply common manipulations like changing volume and adding fade effects, and then export the result to a new file. It includes a fallback to create a dummy WAV file if no input is present, highlighting the dependency on FFmpeg for most real-world formats like MP3.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}