How to combine audio file (wav format) in 1 sec of splice in python?

I am looking for a python function to splicing an audio file (wav format) for 1 second the duration of the splice and store each of the new splice (1 second long) into a new .wav file.

+1
source share
1 answer

Its real simple and simple use of the module pydub, details of which are here and here

pydubhas a method called make_chunksthat you can specify chunk lengthin milliseconds.

make_chunks(your_audio_file_object, chunk_length_ms)

, wav 1 . 8.5 , 9 , playable. .

from pydub import AudioSegment
from pydub.utils import make_chunks

myaudio = AudioSegment.from_file("myAudio.wav" , "wav") 
chunk_length_ms = 1000 # pydub calculates in millisec
chunks = make_chunks(myaudio, chunk_length_ms) #Make chunks of one sec

#Export all of the individual chunks as wav files

for i, chunk in enumerate(chunks):
    chunk_name = "chunk{0}.wav".format(i)
    print "exporting", chunk_name
    chunk.export(chunk_name, format="wav")

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
exporting chunk0.wav
exporting chunk1.wav
exporting chunk2.wav
exporting chunk3.wav
exporting chunk4.wav
exporting chunk5.wav
exporting chunk6.wav
exporting chunk7.wav
exporting chunk8.wav
>>> 
+6

All Articles