audioop-lts

0.2.2 · active · verified Thu Apr 09

audioop-lts is an LTS (Long Term Support) port of Python's built-in `audioop` module, which was deprecated in Python 3.11 and completely removed in Python 3.13. This project aims to maintain the functionality of the `audioop` module for future Python versions, specifically targeting Python 3.13 and greater. It provides operations for manipulating raw audio data, such as adding, averaging, and calculating RMS of sound fragments. The current version is 0.2.2. The library sees releases as needed for maintenance and compatibility with newer Python versions, indicating active maintenance rather than a strict release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic operations using the `audioop-lts` library, which directly replaces the functionality of the removed `audioop` built-in module. It simulates a raw audio fragment and performs RMS calculation, fragment addition, and conversion to u-LAW encoding. Ensure your Python environment is 3.13 or newer.

import audioop

# Simulate a 16-bit mono audio fragment (2 bytes per sample)
# For a real scenario, this would come from an audio file or stream
# Example: two samples, value 1000 and -500
fragment = b'\xe8\x03\x0c\xfe' # Little-endian for 1000 and -500 (approx)
width = 2 # 2 bytes per sample (16-bit)

# Calculate the RMS (Root Mean Square) of the audio fragment
rms_value = audioop.rms(fragment, width)
print(f"RMS value: {rms_value}")

# Add two fragments (requires them to be of the same length and width)
fragment1 = b'\x01\x00\x02\x00'
fragment2 = b'\x05\x00\x06\x00'
sum_fragment = audioop.add(fragment1, fragment2, width)
print(f"Sum fragment: {sum_fragment.hex()}")

# Convert to u-LAW encoding (8-bit output, input width still matters)
u_law_fragment = audioop.lin2ulaw(fragment, width)
print(f"u-LAW fragment: {u_law_fragment.hex()}")

view raw JSON →