Skip to main content

A library for soundscape synthesis and augmentation

Project description

scaper

A library for soundscape synthesis and augmentation

PyPI License Build Status Coverage Status Documentation Status PyPI

Please refer to the documentation for details.

For the motivation behind scaper and its applications check out the scaper-paper:

Scaper: A library for soundscape synthesis and augmentation
J. Salamon, D. MacConnell, M. Cartwright, P. Li, and J. P. Bello
In IEEE Workshop on Applications of Signal Processing to Audio and Acoustics (WASPAA), New Paltz, NY, USA, Oct. 2017.

Installation

Non-python dependencies

Scaper has two non-python dependencies:

Linux/macOS

If you're using Anaconda (or miniconda) to manage your python environment (recommended), you can install these dependencies using conda on macOS/Linux:

conda install -c conda-forge sox ffmpeg

macOS

On macOS these can be installed using homebrew:

brew install sox
brew install ffmpeg

Linux

On linux you can use your distribution's package manager, e.g. on Ubuntu (15.04 "Vivid Vervet" or newer):

sudo apt-get install sox
sudo apt-get install ffmpeg

NOTE: on earlier versions of Ubuntu ffmpeg may point to a Libav binary which is not the correct binary. If you are using Anaconda, you can install the correct version as described earlier by calling conda install -c conda-forge ffmpeg. Otherwise, you can obtain a static binary from the ffmpeg website.

Windows

On windows you can use the provided installation binaries:

Installing Scaper

The simplest way to install scaper is by using pip, which will also install the required python dependencies if needed. To install scaper using pip, simply run:

pip install scaper

To install the latest version of scaper from source, clone or pull the lastest version:

git clone git@github.com:justinsalamon/scaper.git

Then enter the source folder and install using pip to handle python dependencies:

cd scaper
pip install -e .

Tutorial

To help you get started with scaper, please see this step-by-step tutorial.

Example

import scaper
import numpy as np

# OUTPUT FOLDER
outfolder = 'audio/soundscapes/'

# SCAPER SETTINGS
fg_folder = 'audio/soundbank/foreground/'
bg_folder = 'audio/soundbank/background/'

n_soundscapes = 1000
ref_db = -50
duration = 10.0 

min_events = 1
max_events = 9

event_time_dist = 'truncnorm'
event_time_mean = 5.0
event_time_std = 2.0
event_time_min = 0.0
event_time_max = 10.0

source_time_dist = 'const'
source_time = 0.0

event_duration_dist = 'uniform'
event_duration_min = 0.5
event_duration_max = 4.0

snr_dist = 'uniform'
snr_min = 6
snr_max = 30

pitch_dist = 'uniform'
pitch_min = -3.0
pitch_max = 3.0

time_stretch_dist = 'uniform'
time_stretch_min = 0.8
time_stretch_max = 1.2

# Generate 1000 soundscapes using a truncated normal distribution of start times

for n in range(n_soundscapes):

    print('Generating soundscape: {:d}/{:d}'.format(n+1, n_soundscapes))

    # create a scaper
    sc = scaper.Scaper(duration, fg_folder, bg_folder)
    sc.protected_labels = []
    sc.ref_db = ref_db

    # add background
    sc.add_background(label=('const', 'noise'), 
                      source_file=('choose', []), 
                      source_time=('const', 0))

    # add random number of foreground events
    n_events = np.random.randint(min_events, max_events+1)
    for _ in range(n_events):
        sc.add_event(label=('choose', []), 
                     source_file=('choose', []), 
                     source_time=(source_time_dist, source_time), 
                     event_time=(event_time_dist, event_time_mean, event_time_std, event_time_min, event_time_max), 
                     event_duration=(event_duration_dist, event_duration_min, event_duration_max), 
                     snr=(snr_dist, snr_min, snr_max),
                     pitch_shift=(pitch_dist, pitch_min, pitch_max),
                     time_stretch=(time_stretch_dist, time_stretch_min, time_stretch_max))

    # generate
    audiofile = os.path.join(outfolder, "soundscape_unimodal{:d}.wav".format(n))
    jamsfile = os.path.join(outfolder, "soundscape_unimodal{:d}.jams".format(n))
    txtfile = os.path.join(outfolder, "soundscape_unimodal{:d}.txt".format(n))

    sc.generate(audiofile, jamsfile,
                allow_repeated_label=True,
                allow_repeated_source=False,
                reverb=0.1,
                disable_sox_warnings=True,
                no_audio=False,
                txt_path=txtfile)

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

scaper-1.0.3.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

scaper-1.0.3-py2.py3-none-any.whl (23.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file scaper-1.0.3.tar.gz.

File metadata

  • Download URL: scaper-1.0.3.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.6

File hashes

Hashes for scaper-1.0.3.tar.gz
Algorithm Hash digest
SHA256 ab9fc92ff139978905a797998fc71b33da5803453d9e61b3b0dde61dab433bd6
MD5 aed5763207d1af36b32138e23b1759f1
BLAKE2b-256 d5e3c062e6ae842f7a1df775f9b5b5212ffaf17cf1d42ed74f074240b394419d

See more details on using hashes here.

Provenance

File details

Details for the file scaper-1.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: scaper-1.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.6

File hashes

Hashes for scaper-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c9a0e7cc5bea20fc8f1e79157a1dbc9f4a36470f9770225bf14946dcd1b8234a
MD5 3992f622e1aa269c93a4d5edb8fc0d3e
BLAKE2b-256 7e420d6d31020a5ee7b52d4e79c1a9f62146a14dea49165ec2d1a06fc7126731

See more details on using hashes here.

Provenance

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