PyDub: Difference between revisions

From XPUB & Lens-Based wiki
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
aka crash course in [[Python]]
http://pydub.com/
http://pydub.com/
https://github.com/jiaaro/pydub/


https://github.com/jiaaro/pydub/
== Sample audio ==
http://pzwart3.wdka.hro.nl/prototyping/bbcnewssummary.wav


== Installing on OS X ==
== Installing on OS X ==
Line 39: Line 43:


   import pydub
   import pydub
== Simple audio cutting ==
Based on the PyDub page...
<source lang="python">
from pydub import AudioSegment
song = AudioSegment.from_wav("bbcnewssummary.wav")
first = song[:3000]
last = song[-3000:]
x = first + last
x.export("x.wav", format="wav")
</source>
== Loop! ==
<source lang="python">
from pydub import AudioSegment
song = AudioSegment.from_wav("bbcnewssummary.wav")
tape = AudioSegment.silent()
for x in range(120, 0, -1):
    clip = song[x*1000:(x+1)*1000]
    tape = tape + clip
tape.export("tape.wav", format="wav")
</source>
<source lang="python">
from pydub import AudioSegment
song = AudioSegment.from_wav("bbcnewssummary.wav")
tape = AudioSegment.silent()
for x in range(len(song) / 1000, 0, -1):
    clip = song[x*1000:(x+1)*1000]
    tape = tape + clip
tape.export("tape.wav", format="wav")
</source>

Latest revision as of 17:31, 4 November 2014

aka crash course in Python

http://pydub.com/ https://github.com/jiaaro/pydub/

Sample audio

http://pzwart3.wdka.hro.nl/prototyping/bbcnewssummary.wav

Installing on OS X

  • Download the latest code (as a zip)
  • Open the Terminal
  • "cd" into the folder with setup.py
sudo python setup.py install

If it complains about setuptools missing, do this:

sudo easy_install setuptools

... and then repeat the line above.


Linux

  • Download the latest code (as a zip)
  • Open the Terminal
  • "cd" into the folder with setup.py
sudo python setup.py install

If it complains about setuptools missing, do this:

sudo apt-get install python-setuptools

... and then repeat the line above.

Running / Using pydub

  • Open terminal
  • Start "python"
  import pydub

Simple audio cutting

Based on the PyDub page...

from pydub import AudioSegment

song = AudioSegment.from_wav("bbcnewssummary.wav")
first = song[:3000]
last = song[-3000:]
x = first + last
x.export("x.wav", format="wav")

Loop!

from pydub import AudioSegment
 
song = AudioSegment.from_wav("bbcnewssummary.wav")
tape = AudioSegment.silent()
for x in range(120, 0, -1):
    clip = song[x*1000:(x+1)*1000]
    tape = tape + clip
tape.export("tape.wav", format="wav")
from pydub import AudioSegment
 
song = AudioSegment.from_wav("bbcnewssummary.wav")
tape = AudioSegment.silent()
for x in range(len(song) / 1000, 0, -1):
    clip = song[x*1000:(x+1)*1000]
    tape = tape + clip
tape.export("tape.wav", format="wav")