VOOZH about

URL: https://www.geeksforgeeks.org/python/working-with-wav-files-in-python-using-pydub/

⇱ Working with wav files in Python using Pydub - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Working with wav files in Python using Pydub

Last Updated : 20 Mar, 2024

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.

Installation

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:

  1. Playing audio file.
  2. We can get certain information of file like length channels.
  3. Increase/Decrease volume of given .wav file.
  4. Merging two or more audio files.
  5. Exporting an audio file.
  6. Splitting an audio file.

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
Comment
Article Tags: