Audio resampler library for python. Can convert audio between different PCM audio formats.
Project description
Audio Resampler
Audio Resampler is a Python library designed for converting audio data between different formats and sample rates. It supports PCM and u-law audio formats and provides a flexible API for audio processing.
Features
- Convert audio data between PCM and u-law formats.
- Resample audio data to different sample rates.
- Support for various bit depths.
- Easy-to-use API with configuration options.
Installation
To install the library, use pip:
pip install audio-pcm-resampler
Usage
Basic Example
Convert PCM format to PCM
from audio_pcm_resampler.audio_resampler import AudioResampler, AudioResamplerConfig
from audio_pcm_resampler.audio_format import PCMFormat, ULAWFormat, BitDepth
from audio_pcm_resampler.data_type_conversion import bytes_2_numpy
# open input file
file = "I_want_to_create_the_world_int16_8khz.wav"
from audio_pcm_resampler.open_wav import open_wav_file
audio = open_wav_file(file)
# Initialize the resampler
resampler = AudioResampler(AudioResamplerConfig(
# Input format must match the one from the file
input_format=PCMFormat(
sample_rate=audio.params.framerate,
bit_depth=BitDepth.INT16,
),
output_format=PCMFormat(
sample_rate=24_000,
bit_depth=BitDepth.INT16,
)
))
# Process PCM input audio data, must use NDArray as input
input_data = bytes_2_numpy(audio.frames, resampler.config.input_format.bit_depth.to_numpy())
output_data = resampler.process(input_data)
Convert PCM to ULAW
from audio_pcm_resampler.audio_resampler import AudioResampler, AudioResamplerConfig
from audio_pcm_resampler.audio_format import PCMFormat, ULAWFormat, BitDepth
from audio_pcm_resampler.data_type_conversion import bytes_2_numpy
# open input file
file = "I_want_to_create_the_world_int16_8khz.wav"
from audio_pcm_resampler.open_wav import open_wav_file
audio = open_wav_file(file)
# Initialize the resampler
resampler = AudioResampler(AudioResamplerConfig(
# Input format must match the one from the file
input_format=PCMFormat(
sample_rate=audio.params.framerate,
bit_depth=BitDepth.INT16,
),
output_format=ULAWFormat()
))
# Process PCM input audio data, must use NDArray as input
input_data = bytes_2_numpy(audio.frames, resampler.config.input_format.bit_depth.to_numpy())
output_data = resampler.process(input_data)
Requirements
- Python >= 3.10
- NumPy
- Pydantic
- soxr
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file audio_pcm_resampler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: audio_pcm_resampler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.9.14 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4965fdbd7dd1d9c02af501464d4fae7f62c323c8b2050a91448f088c9909ddd
|
|
| MD5 |
ce9e41454800aa87bc17c776490c92ec
|
|
| BLAKE2b-256 |
91953affae69f2d105162f584a1f14d66c428d356aefe7a7fc4ecc4edf8681d7
|