简体   繁体   English

无法使用声音文件将音频存储为 MP3 文件

[英]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.

相关问题 有没有办法使用 python 将 mp3/音频文件输入到麦克风输入? - Is there a way using python to input a mp3/audio file to a microphone input? 当我将 mp3 文件放到 window 上时,为什么会出现错误“pygame.error:无法读取前 12 个字节的音频数据”? - Why do I get the error, "pygame.error: Couldn't read first 12 bytes of audio data" when I drop a mp3 file on to the window? 如何在 Python 上将 .mp3 文件作为音频播放 - How to play .mp3 file as an audio on Python 用Python分割MP3音频文件 - MP3 audio file splitting with Python 如何使用 Python 将音频文件(.mp3 或 .wav 或任何其他文件)转换为唯一的音频 ID? - How to convert an audio file (.mp3 or .wav or any other) to an unique audio id using Python? 无法在 Windows 上使用 winsound 播放 .mp3 文件 - Can't play .mp3 file using winsound on windows MP3音频Python - MP3 Audio Python 如何使用python脚本停止/关闭音频文件(mp3 / .wav) - how to stop/close an audio file(mp3/.wav) using python script 提供将mp3中的mp3转换为wav文件以及使用python进行音频处理的教程的方法[pymedia] - Provision to convert mp3 to wav file in python and tutorial for audio processing using python [pymedia] 如何使用 pydub Python 加载超过 4GB 的 mp3 音频文件 - How to load mp3 audio file more than 4GB using pydub Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM