Update:
一个音频重采样并保存的脚本。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import librosa | |
import os | |
from tkinter import Tk | |
from tkinter import filedialog | |
resample_sr = input("target sr (kHz):") | |
resample_sr = int(resample_sr)*1000 | |
Tk().withdraw() | |
filename = filedialog.askopenfilename(initialdir = './',title = "Select file") | |
new_filename = filename.replace(os.path.splitext(filename)[-1],'-'+str(resample_sr)+'.wav') | |
y, sr = librosa.load(filename, sr = resample_sr) | |
librosa.output.write_wav(new_filename, y, resample_sr) |
python中的 librosa.resample()
让我们可以非常方便的对音频文件进行重采样。
1 | import librosa |
目标是一个48kHz的音频
利用librosa库中中的resample
将这段音频下采样到8kHz。