improve audio resampling by switching from resampy to soxr
This commit is contained in:
@@ -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`.
|
- Fixed a type error when using `voice_settings` in `ElevenLabsHttpTTSService`.
|
||||||
|
|
||||||
|
### Performance
|
||||||
|
|
||||||
|
- Replaced audio resampling library `resampy` with `soxr`.
|
||||||
|
|
||||||
## [0.0.53] - 2025-01-18
|
## [0.0.53] - 2025-01-18
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ dependencies = [
|
|||||||
"protobuf~=5.29.3",
|
"protobuf~=5.29.3",
|
||||||
"pydantic~=2.10.5",
|
"pydantic~=2.10.5",
|
||||||
"pyloudnorm~=0.1.1",
|
"pyloudnorm~=0.1.1",
|
||||||
"resampy~=0.4.3"
|
"soxr~=0.5.0"
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ import audioop
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pyloudnorm as pyln
|
import pyloudnorm as pyln
|
||||||
import resampy
|
import soxr
|
||||||
|
|
||||||
|
|
||||||
def resample_audio(audio: bytes, original_rate: int, target_rate: int) -> bytes:
|
def resample_audio(audio: bytes, original_rate: int, target_rate: int) -> bytes:
|
||||||
if original_rate == target_rate:
|
if original_rate == target_rate:
|
||||||
return audio
|
return audio
|
||||||
audio_data = np.frombuffer(audio, dtype=np.int16)
|
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()
|
return resampled_audio.astype(np.int16).tobytes()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user