From cacd6ba3fa7a9e5988952519d2475e59094212ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 21 Jan 2025 13:31:33 -0800 Subject: [PATCH 1/2] improve audio resampling by switching from resampy to soxr --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- src/pipecat/audio/utils.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0d48cbaa..445fc3993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a type error when using `voice_settings` in `ElevenLabsHttpTTSService`. +### Performance + +- Replaced audio resampling library `resampy` with `soxr`. + ## [0.0.53] - 2025-01-18 ### Added diff --git a/pyproject.toml b/pyproject.toml index 57d1f2703..0d5e605d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ dependencies = [ "protobuf~=5.29.3", "pydantic~=2.10.5", "pyloudnorm~=0.1.1", - "resampy~=0.4.3" + "soxr~=0.5.0" ] [project.urls] diff --git a/src/pipecat/audio/utils.py b/src/pipecat/audio/utils.py index 143f05c28..7ed44befd 100644 --- a/src/pipecat/audio/utils.py +++ b/src/pipecat/audio/utils.py @@ -8,14 +8,14 @@ import audioop import numpy as np import pyloudnorm as pyln -import resampy +import soxr def resample_audio(audio: bytes, original_rate: int, target_rate: int) -> bytes: if original_rate == target_rate: return audio audio_data = np.frombuffer(audio, dtype=np.int16) - resampled_audio = resampy.resample(audio_data, original_rate, target_rate) + resampled_audio = soxr.resample(audio_data, original_rate, target_rate) return resampled_audio.astype(np.int16).tobytes() From f23baa78d850da547322dd4421a9428c647cfa0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Tue, 21 Jan 2025 17:34:48 -0800 Subject: [PATCH 2/2] test-requirements: add soxr and remove resampy --- test-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-requirements.txt b/test-requirements.txt index f974121b0..36e64060b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -22,8 +22,8 @@ pydantic~=2.8.2 pyloudnorm~=0.1.1 pyht~=0.1.4 python-dotenv~=1.0.1 -resampy~=0.4.3 silero-vad~=5.1 +soxr~=0.5.0 together~=1.2.7 transformers~=4.44.0 websockets~=13.1