Reputation: 2356
Now, I have to split a mp3 file into several parts. I use python to do the work. But I cannot find a good library to do this job. I've already tried pymp3cut, echo-nest-remix, but it cannot work well.
So is there any better choice?
Upvotes: 0
Views: 2161
Reputation: 1636
good choice might be librosa
, your just split array using sample rate and desirable seconds, in example below number of seconds - 2
import librosa
import soundfile as sf
audio_file = "your_example.mp3"
y, sr = librosa.load(audio_file, sr=None)
# chunk duration 2 seconds
chunk_duration = 2
chunk_samples = int(chunk_duration * sr)
chunks = [y[i:i + chunk_samples] for i in range(0, len(y), chunk_samples)]
for i, chunk in enumerate(chunks):
output_file = f"chunk_{i}.mp3"
sf.write(output_file, chunk, sr)
Upvotes: 0
Reputation: 9680
I have been using VLC's python binding http://wiki.videolan.org/Python_bindings to convert videos and split into frames. VLC supports MP3 but I must admit I have not used it with audio.
Upvotes: 1