Skip to main content

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

Radovan Zivkovic

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

audio_pcm_resampler-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file audio_pcm_resampler-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for audio_pcm_resampler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4965fdbd7dd1d9c02af501464d4fae7f62c323c8b2050a91448f088c9909ddd
MD5 ce9e41454800aa87bc17c776490c92ec
BLAKE2b-256 91953affae69f2d105162f584a1f14d66c428d356aefe7a7fc4ecc4edf8681d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page