[go: up one dir, main page]

0% found this document useful (0 votes)
133 views4 pages

Audio Processing Packages

Pydub, Wave, SoundFile, SoundDevice, and Pyo are Python packages for audio processing. Pydub allows opening, modifying, and exporting audio files in different formats. It can apply gain, overlay audios, and change speed. Wave provides an interface for the WAV format. SoundFile reads and writes audio files in various formats using NumPy arrays. SoundDevice plays and records audio using PortAudio and NumPy. Pyo contains tools for signal processing and artistic audio manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views4 pages

Audio Processing Packages

Pydub, Wave, SoundFile, SoundDevice, and Pyo are Python packages for audio processing. Pydub allows opening, modifying, and exporting audio files in different formats. It can apply gain, overlay audios, and change speed. Wave provides an interface for the WAV format. SoundFile reads and writes audio files in various formats using NumPy arrays. SoundDevice plays and records audio using PortAudio and NumPy. Pyo contains tools for signal processing and artistic audio manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

RELAY Members:

Laurenz Garcia | Jamahl Decrepito | Krizza Mae MAningding | Maureen Rama | Sanly Alagos

Audio Processing Packages

Pydub
Github link: https://github.com/jiaaro/pydub

Pydub is a python package that can read mp3, flv, ogg , wav, and raw files. With
pydub, users are able to modify the audio file as well as read parameters such as bitrate,
maximum sound amplitude, length, and know the number of channels. Modification of
the audio source can also be done such as applying positive or negative gain, changing
the bitrate, speeding up, slowing down, adding together audio as well as overlaying
audios together.
Below are sample codes for pydub demonstrating the different functions built
within the library:
Opening audio files and saving the file to a variable:
audio_1=AudioSegment.from_file("C:\\Users\\Laurenz Clyde\\Desktop\\
3rd ECE\\programming\\jojo_edit.mp3" ,"mp3")
play(audio_1)
Applying audio gain:
play(audio_1.apply_gain(20))
Applying attenuation, or negative gain:
play(audio_1.apply_gain(-8))
Exporting the edited audio:
audio_1.apply_gain(20).export(out_f="jojo_butlouder.mp3", format =
"mp3")
In pydub, users will be able to export the audio file to different formats.
audio_1.export(out_f="Wave_Sound.wav", format = "wav")
Overlaying audio files to mix two audio file to play at the same time.
beat = AudioSegment.from_file("C:\\Users\\Laurenz Clyde\\Desktop\\3rd
ECE\\programming\\beat.mp3" ,"mp3")
violin = AudioSegment.from_file("C:\\Users\\Laurenz Clyde\\Desktop\\3rd
ECE\\programming\\la_campanella.mp3" ,"mp3")
mixed_audio = beat.overlay(violin.apply_gain(10))
play(mixed_audio.)

Wave
Github Link: https://github.com/python/cpython/blob/main/Lib/wave.py
The wave module is a built-in module that does not require you to install
anything. It provides a practical interface for the WAV audio format. The functions in this
module can read the properties from a WAV file and output audio data in raw format to
an object that resembles a file. It supports mono and stereo but does not support
compression or decompression.

SoundFile
Github link: https://github.com/bastibe/python-soundfile/blob/master/soundfile.py
This python package for audio processing is an audio library based on libsndfile,
CFFI, and NumPy. In modern Python, run pip install soundfile to download and install
the most recent version of SoundFile and its dependencies. This will also install the
libsndfile library on OS X and Windows. It can be used for simply reading and writing
different formats like WAV, FLAC, OGG, and MAT. Basically in this package, audio files
can be read using the read() function and we can write a file using the write() function.
Since the sampling rate has a standard value, a NumPy array (i.e., data) is required to
write an audio file. It opens the file in binary mode for writing where the software will
rewrite it if the same name already exists.
Over the past several releases, SoundFile has seen a rapid change. The import
name was updated in version 0.7 from import pysoundfile to import soundfile.

SoundDevice
Github link: https://github.com/spatialaudio/python-sounddevice/
SoundDevice or also known as python-sounddevice is a python module for cross
- platform audio playback. This Python module provides bindings for the PortAudio
library and a few convenience functions to play and record NumPy arrays containing
audio signals. Installation of Numpy and soundfile must be done to open WAV files as
conversion of WAV files to NumArrays is necessary to open audio file format (WAV).
Coding in python using the sounddevice module includes a statement which is
used for extracting the raw audio data and also the sampling rate of the file, and another
statement to make sure that script will only be terminated after finishing the audio.

Pyo
Github link: https://github.com/belangeo/pyo
A Python library called pyo has classes for several different kinds of audio signal
processing. Through the usage of the Python interpreter, users will be able to easily
embed signal processing chains in Python scripts or projects and alter them there. Pyo’s
module tools provide fundamental signal processing (filters, delays, synthesis
generators, etc.) and mathematical operations on audio signals, as well as more
advanced algorithms for sound granulation and other artistic audio manipulations. pyo
supports the MIDI standard for setting up sound events and managing process settings
as well as the OSC protocol (Open Sound Control) to facilitate communication across
softwares. With all the advantages of an established, well-liked general programming
language, pyo enables the development of complex signal processing chains.
RELAY Members:
Laurenz Garcia | Jamahl Decrepito | Krizza Mae MAningding | Maureen Rama | Sanly Alagos

from pydub import AudioSegment


from pydub.playback import play

# %%
audio_1 = AudioSegment.from_file("C:\\Users\\Laurenz Clyde\\Desktop\\3rd ECE\\
programming\\jojo_edit.mp3" ,"mp3")
play(audio_1)

# %%
play(audio_1.apply_gain(20))

# %%
audio_1.apply_gain(20).export(out_f="jojo_butlouder.mp3", format = "mp3")

audio_2 = AudioSegment.from_file("C:\\Users\\Laurenz Clyde\\Desktop\\3rd ECE\\


programming\\jojo_butlouder.mp3" ,"mp3")

# %%
audio_1.export(out_f="Wave_Sound.wav", format = "wav")

# %%
play(audio_1.apply_gain(-8))

# %%
print(audio_1.channels)

# %%
print(audio_1.frame_rate)  #fidelity #bitrate

# %%
print(audio_1.duration_seconds)           #length

# %%
print(audio_1.apply_gain(-8).max)
print(audio_1.max)
print(audio_2.max)

# %%
play(audio_2.speedup(2))

# %%
def speed_change(sound, speed=1.0):
    sound_with_altered_frame_rate = sound._spawn(sound.raw_data, overrides={
        "frame_rate": int(sound.frame_rate * speed)
    })

    return sound_with_altered_frame_rate.set_frame_rate(sound.frame_rate)

slow_sound = speed_change(audio_2, speed=0.75)


play(slow_sound)

# %%
beat = AudioSegment.from_file("C:\\Users\\Laurenz Clyde\\Desktop\\3rd ECE\\
programming\\beat.mp3" ,"mp3")
play(beat)

# %%
violin = AudioSegment.from_file("C:\\Users\\Laurenz Clyde\\Desktop\\3rd ECE\\
programming\\la_campanella.mp3" ,"mp3")
play(violin.apply_gain(20))

# %%
#violin_slower = speed_change(violin, speed)

mixed_audio = beat.overlay(violin.apply_gain(10))
play(mixed_audio.)

You might also like