?方案1:使用pydub 處理
from pydub import AudioSegment
sound = AudioSegment.from_file(r"D:\websiteDownload\我今天被一件事情搞得很煩.wav")
print(sound.duration_seconds)
rate = 0.75
sound_with_altered_frame_rate = sound._spawn(sound.raw_data, overrides={"frame_rate": int(sound.frame_rate * rate)})
sound_slow = sound_with_altered_frame_rate.set_frame_rate(sound.frame_rate)
print(sound_slow.duration_seconds)
sound_slow.export(r"D:\websiteDownload\我今天被一件事情搞得很煩new.wav", format="wav")
聽到處理結果的感受,語速慢了,但是音色也變了
方案2:
import librosa
import soundfile as sfaudio_path = r"D:\websiteDownload\我今天被一件事情搞得很煩.wav"
y, sr = librosa.load(audio_path, sr=None) # sr=None 保持原始采樣率# 變速處理,比如加速1.5倍
y_change = librosa.effects.time_stretch(y,rate=0.75)
#保存
sf.write(r"D:\websiteDownload\我今天被一件事情搞得很煩new2.wav", y_change, sr)
聽到處理結果的感受,語速慢了,但是音色不變