17

I've found pyDub, and it seems like just what I need:

http://pydub.com/

The only issue is with generating silence. Can pyDub do this?

Essentially the workflow I want is:

  1. Take all the WAV files in a directory
  2. Piece them together in filename order with 1 sec of silence in between
  3. Generate a single MP3 of the result

Is this possible? I realize I could create a WAV of silence and do it that way (spacer GIF flashback, anyone?), but I'd prefer to generate the silence programmatically, because I may want to experiment with the duration of silence and/or the bitrate of the MP3.

I greatly appreciate any responses.

1
  • 1
    +1 I do have flashbacks of spacer gifs Commented May 16, 2014 at 4:12

1 Answer 1

44

The pydub sequences are composed of pydub.AudioSegment instances. The pydub quickstart documentation only shows how to create AudioSegments from files.

However, reading the source, or even more easily, running pydoc pydub.AudioSequence reveals

pydub.AudioSegment = class AudioSegment(__builtin__.object) | AudioSegments are *immutable* objects representing segments of audio | that can be manipulated using python code. … | silent(cls, duration=1000) from __builtin__.type | Generate a silent audio segment. | duration specified in milliseconds (default: 1000ms). 

which would be called like (following the usage in the quick start guide):

from pydub import AudioSegment second_of_silence = AudioSegment.silent() # use default second_of_silence = AudioSegment.silent(duration=1000) # or be explicit 

now second_of_silence would be an AudioSegement just like song in the example

song = AudioSegment.from_wav("never_gonna_give_you_up.wav") 

and could be manipulated, composed, etc. with no blank audio files needed.

Sign up to request clarification or add additional context in comments.

5 Comments

As the author of pydub I can verify that this ought to be the accepted answer :)
@Jiaaro As someone who has just been made aware of pydub, allow me to complement you on the clarity of the API; it makes me wish I had audio compositing to do.
Thanks a lot, msw (and Jiaaro for confirming the answer)!
@msw Is it possible to add this silence to an existing audio?
@YasserKhalil Yes, just use + between the silence AudioSegment and other AudioSegment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.