Skip to main content

Some audio effects such as delay, speed changes implemented in python

Project description

audio_effects

This is a python package with some audio effects functions such as delay, speed changes implemented in python, with the help of pydub and numpy.

Installation

You can install this package via pip, run this line in cmd/terminal

pip install audio_effects

Importing

import audio_effects as ae
from pydub import AudioSegment
from pydub.playback import _play_with_simpleaudio as play_sound

Usage

delay

This delay function adds delay effects to audio using pydub, the delay sounds would be decreasing volume one by one, placing at a interval one after another after the original sound. The return value is a new pydub AudioSegment instance with the delay effects added.

delay(sound, interval=0.5, unit=6, volumes=None, decrease_unit=None)

# sound: a pydub AudioSegment instance

# interval: the time between each delay sound in seconds

# unit: the number of the delay sounds

# volumes: you can specify the volume of each delay sound using this parameter,
# could be a list or tuple, the elements are volume percentages (from 0 to 100)

# decrease_unit: you can specify the decrease unit (in percentages) of the volumes
# of the delay sounds using this parameter


# examples
current_audio = AudioSegment.from_file('Cmaj7_chord.mp3')
current_bpm = 130
current_interval = ae.bar_to_real_time(3 / 16, current_bpm, 1) / 1000
current_audio_with_delay = ae.delay(current_audio,
                                    interval=current_interval,
                                    unit=10)
play_sound(current_audio_with_delay) # listen to the delay effects

The delay function works really well as expected, given precise time interval between each delay sound and the number of delay sounds, you can make custom delay effects on audio files.

speed down

There is already a speedup function implemented in pydub, which is useful, but currently there are no speed down function in pydub, so I give it a try.

This speed_down function is my attempt at making a speed down function of pydub AudioSegment, the basic idea is firstly we cut the sound into n pieces of chunks, and then we copy each chunk and paste it right after itself, we use the speed changes to determine how much copies of each chunk we should get, and then put every chunk with its copied chunks back to a silent audio of length after speed changes, then we can get the slow down audio while remain the pitch unchanged. The return value is a new pydub AudioSegment instance that the speed slows down.

Update 2021/9/8 It basically works now to some extent, but still very far from what could be considered good, you can set the parameters of this function to achieve various of slow down effects of the audio, the suitable parameters for different audio files to get a good slow down effect might be different.

speed_down(sound,
           speed_changes,
           chunk_size=50,
           crossfade=25,
           merge_crossfade=25,
           crossfade_threshold=10)

# sound: a pydub AudioSegment instance

# speed_changes: the ratio of the speed to change, 1 means no speed changes,
# < 1 means slow down, for example, 0.5 means half the speed,
# note that this function only works for speed to slow down, if you want to speed up, please use
# the speedup function of pydub, which you pass speed ratio > 1 to speed up the audio

# chunk_size: the chunk size of the audio to be cut in, in ms

# crossfade: the time of fading effects between 2 adjacent chunks when concatenating
# the duplicates of each chunk, in ms

# merge_crossfade: the time of fading effects between 2 adjacent chunks when concatenating
# the chunks after the duplicating process, in ms

# crossfade_threshold: the minimum value of crossfade, in ms


# examples
current_audio = AudioSegment.from_file('Cmaj7_chord.mp3')
speed_change_ratio = 0.7
current_audio_slow_down = ae.speed_down(current_audio, speed_change_ratio)
play_sound(current_audio_slow_down) # listen to the slow down version of the audio

There will be more on the list, I will document some other functions here when I have time

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

audio_effects-0.22.tar.gz (62.1 kB view details)

Uploaded Source

File details

Details for the file audio_effects-0.22.tar.gz.

File metadata

  • Download URL: audio_effects-0.22.tar.gz
  • Upload date:
  • Size: 62.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.9

File hashes

Hashes for audio_effects-0.22.tar.gz
Algorithm Hash digest
SHA256 dc9e7f051c9ec09eabb39be8e2b910abb5978dac469cba5e090714dc3b1520e6
MD5 75b996fe1fe742cb31aa9271ae16e7bd
BLAKE2b-256 afb9ff6610e40387550a77a80bae47d4e5ecbba03f6f7818aba8d350afb44f36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page