[英]Couldn't store audio as MP3 file using soundfile
My intention is to process MP3 file using Librosa library (normalize volume, trim silences, etc).我的意图是使用Librosa库处理 MP3 文件(标准化音量、修剪静音等)。 However, as Librosa doesn't support MP3 format I use audioread library to load audio;
但是,由于 Librosa 不支持 MP3 格式,我使用audioread库来加载音频; however, I could not find the function in audioread that writes back the file, for that purpose I have loaded soundfile and saved processed file into WAV.
但是,我在audioread中找不到写回文件的function,为此我已经加载了声音文件并将处理后的文件保存到WAV中。 Unfortunately, I am able to save only one channel (MONO) not Stereo.
不幸的是,我只能保存一个通道(单声道)而不是立体声。 Kindly advise, what library can I use to load and write MP3 file and process it using Librosa?
请告知,我可以使用什么库来加载和编写 MP3 文件并使用 Librosa 处理它? or how can I write both channels into WAV or MP3 using soundfile?
或者如何使用声音文件将两个通道写入 WAV 或 MP3?
import audioread, librosa
import soundfile as sf
filename="../sounds/music.mp3"
audio_file = audioread.audio_open(filename)
audio, sr = librosa.load(audio_file, sr= 44100)
clip = librosa.effects.trim(audio, top_db= 10)
sf.write('../sounds/output/out.wav', clip[0], sr, 'PCM_24')
Soundfile supports multichannel saving just fine. Soundfile 支持多声道保存就好了。 However, Librosa works with audio arrays where the dimensions are: (N_channels, N_samples).
但是,Librosa 与音频 arrays 一起使用,其中尺寸为:(N_channels,N_samples)。 Soundfile on the other hand works with: (N_samples, N_channels).
另一方面,声音文件适用于:(N_samples,N_channels)。 You can use numpy to transpose from one format to the other:
您可以使用 numpy 将一种格式转换为另一种格式:
sf.write('../sounds/output/out.wav', np.transpose(clip), sr, 'PCM_24')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.