![]() |
VOOZH | about |
Audio files are a widespread means of transferring information. So let's see how to work with audio files using Python. Python provides a module called pydub to work with audio files. pydub is a Python library to work with only .wav files. By using this library we can play, split, merge, edit our .wav audio files.
This module does not come built-in with Python. To install it type the below command in the terminal.
pip install pydub
Following are some functionalities that can be performed by pydub:
Let's see the code for some functionalities of pydub library:
1) Playing Audio File: This is done using play() method.
Output:
2) Knowing about .wav file: for this we will use attributes of audio file object.
Output:
<class 'pydub.audio_segment.AudioSegment'> 22050 1 2 17106 60000 50
3) Increasing/Decreasing volume of the file: By using '+' and '-' operator.
Output:
4) Merging files: This is done using '+' operator.
Output:
5) Exporting files: This is done using export() method.
Output:
6) Splitting Audio: Splitting audio using split_to_mono() method.
Output:
[<pydub.audio_segment.AudioSegment object at 0x000001358727E860>, <pydub.audio_segment.AudioSegment object at 0x000001358721F978>] 1