Skip to content

Commit

Permalink
💩 revert libsora => pyrubberband
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed Jun 24, 2024
1 parent 7fa55d9 commit 4ead989
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
19 changes: 6 additions & 13 deletions modules/utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import soundfile as sf
from pydub import AudioSegment, effects
import librosa
import pyrubberband as pyrb

INT16_MAX = np.iinfo(np.int16).max

Expand Down Expand Up @@ -90,28 +90,21 @@ def apply_prosody_to_audio_segment(
return audio_segment


# FIXME: 使用 librosa.effects 会有音质损失
def apply_prosody_to_audio_data(
audio_data: np.ndarray,
rate: float = 1,
volume: float = 0,
pitch: int = 0,
pitch: float = 0,
sr: int = 24000,
) -> np.ndarray:
if audio_data.ndim != 1:
audio_data = audio_data.mean(axis=1)
if rate != 1:
audio_data = pyrb.time_stretch(audio_data, sr=sr, rate=rate)

# Adjust volume
if volume != 0:
audio_data = audio_data + volume

# Adjust rate (speed)
if rate != 1:
audio_data = librosa.effects.time_stretch(audio_data, rate=rate)
audio_data = audio_data * volume

# Adjust pitch
if pitch != 0:
audio_data = librosa.effects.pitch_shift(audio_data, sr=sr, n_steps=pitch)
audio_data = pyrb.pitch_shift(audio_data, sr=sr, n_steps=pitch)

return audio_data

Expand Down
3 changes: 2 additions & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,5 @@ watchfiles==0.22.0
websockets==11.0.3
Werkzeug==3.0.3
zhon==2.0.2
ftfy==6.2.0
ftfy==6.2.0
pyrubberband==0.3.0
3 changes: 2 additions & 1 deletion requirements.docker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ cn2an
# audio_denoiser
python-box
ftfy
librosa
librosa
pyrubberband
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ cn2an
# audio_denoiser
python-box
ftfy
librosa
librosa
pyrubberband

0 comments on commit 4ead989

Please sign in to comment.