{"library":"sox","title":"Python SoX Wrapper","type":"library","description":"The `sox` library provides a Python wrapper around the SoX (Sound eXchange) command-line tool, enabling Python programs to perform audio processing tasks such as format conversion, effects application, and mixing. The current version is 1.5.0, released in late 2023, and it generally follows a release cadence tied to significant feature additions or Python version support updates.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install sox"],"cli":null},"imports":["import sox","from sox import Transformer"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/rabitt/pysox","docs":null,"changelog":null,"pypi":"https://pypi.org/project/sox/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import sox\nimport os\nimport subprocess\n\ninput_file = \"input_audio.wav\"\noutput_file = \"output_processed.wav\"\n\n# --- Pre-requisite Check: SoX command-line tool ---\ntry:\n    subprocess.run([\"sox\", \"--version\"], check=True, capture_output=True)\nexcept (subprocess.CalledProcessError, FileNotFoundError):\n    print(\"WARNING: The SoX command-line tool is not found. Please install it first.\")\n    print(\"  (e.g., `sudo apt-get install sox` on Debian/Ubuntu, `brew install sox` on macOS)\")\n    # Exit or provide placeholder if SoX isn't installed. For quickstart, we'll print and continue\n    # to show the Python API, but expect actual failure if SoX isn't present.\n\n# --- Generate a dummy input file if it doesn't exist ---\nif not os.path.exists(input_file):\n    print(f\"Generating dummy '{input_file}' for the example...\")\n    try:\n        # Use SoX itself to create a 1-second sine wave file\n        subprocess.run([\"sox\", \"-n\", input_file, \"synth\", \"1\", \"sine\", \"440\"], check=True)\n        print(f\"Successfully generated '{input_file}'.\")\n    except (subprocess.CalledProcessError, FileNotFoundError):\n        print(f\"Failed to generate '{input_file}'. Please ensure SoX is installed and accessible in PATH, or provide your own '{input_file}'.\")\n\n# --- SoX Transformation Example ---\nif os.path.exists(input_file):\n    # Initialize a Transformer object\n    tfm = sox.Transformer()\n\n    # Apply some audio effects\n    tfm.trim(0.1, 0.9) # Trim from 0.1s to 0.9s\n    tfm.set_output_format(rate=16000, channels=1) # Resample to 16kHz mono\n    tfm.compand(attack=0.3, decay=0.8, soft_knee=6, threshold=-40, ratio=5) # Apply dynamic range compression\n\n    # Build the output file. The 'build' method executes the SoX command.\n    try:\n        tfm.build(input_file, output_file)\n        print(f\"Transformation complete! Output saved to '{output_file}'.\")\n        print(f\"Original file size: {os.path.getsize(input_file)} bytes\")\n        print(f\"Processed file size: {os.path.getsize(output_file)} bytes\")\n    except sox.SoxError as e:\n        print(f\"Error during SoX transformation: {e}\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\nelse:\n    print(\"Skipping transformation: Input file not found.\")\n\n# --- Clean up (optional) ---\n# if os.path.exists(output_file):\n#     os.remove(output_file)\n# if os.path.exists(input_file):\n#     os.remove(input_file)\n","lang":"python","description":"This quickstart demonstrates how to use `sox.Transformer` to apply effects and convert an audio file. It includes checks for the external SoX command-line tool and generates a dummy input file if one isn't present to make the example runnable.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"1.5.0","pypi_latest":"1.5.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":4.7,"avg_import_s":0.32,"wheel_type":"sdist"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":null,"import_time_s":0.28,"mem_mb":8.8,"disk_size":"91.4M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":4.3,"import_time_s":0.23,"mem_mb":8.8,"disk_size":"88M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":null,"import_time_s":0.38,"mem_mb":9.7,"disk_size":"99.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":4.1,"import_time_s":0.38,"mem_mb":9.7,"disk_size":"95M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":null,"import_time_s":0.39,"mem_mb":9.4,"disk_size":"86.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":5.1,"import_time_s":0.4,"mem_mb":9.4,"disk_size":"82M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":null,"import_time_s":0.29,"mem_mb":9.3,"disk_size":"85.5M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":5,"import_time_s":0.36,"mem_mb":9.3,"disk_size":"81M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":null,"import_time_s":0.22,"mem_mb":8.6,"disk_size":"99.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"sox","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"noisy","install_time_s":5,"import_time_s":0.29,"mem_mb":8.6,"disk_size":"98M"}]}}