Creating silence with pyDub

I found pyDub and it seems to me that I need:

http://pydub.com/

The only problem is creating silence. Can pyDub do this?

Essentially the workflow that I want:

  • Take all the wav files in the directory
  • Put them together in order of file names with 1 second of silence between
  • Create one MP3 result

Is it possible? I understand that I can create silence WAV and do so (GIF-flashback spacer, anyone?), But I would prefer to generate silence programmatically, because I can experiment with the silence duration and / or MP3 bitrate.

I really appreciate any answers.

+6
source share
1 answer

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

However, after reading the source or, even easier, running pydoc pydub.AudioSequence shows

 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 will be called (after use 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 will be an AudioSegement just like the song in the example

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

and it could be manipulated, arranged, etc. without any empty audio files.

+8
source

Source: https://habr.com/ru/post/969366/


All Articles