0
我想重新採樣在40.000赫茲到44100赫茲錄製的單聲道錄音。librosa write_wav in mono?
下面的作品,但librosa代碼似乎立體聲保存,使文件的兩倍這是沒有必要的規模和我有很多的樣品進行處理的。
所以我需要保存結果單。
代碼:
# resampling a .wav file to a specific sample rate
import os
import librosa
import resampy
# this is the sample reate we want
sr_target = 44100
directory_in_str = '/home/hugo/test/'
directory = os.fsencode(directory_in_str)
for file in os.listdir(directory):
filename = os.fsdecode(file)
if filename.endswith(".wav"):
file_path = os.path.join(directory_in_str, filename)
print(file_path)
# Load in librosa's example audio file at its native sampling rate
x, sr_orig = librosa.load(file_path, mono=True, sr=None)
print("Original sample rate is : ", sr_orig)
# x is now a 1-d numpy array, with `sr_orig` audio samples per second
# We can resample this to any sampling rate we like, say 16000 Hz
y = resampy.resample(x, sr_orig, sr_target)
file_path_new = os.path.join(directory_in_str+'new/', filename)
# write it back
librosa.output.write_wav(file_path_new, y, sr_target)
continue
else:
continue
問:我想保存單重採樣文件,我得到立體聲,沒有選項只保存單...