Package: scaper
scaperA library for soundscape synthesis and augmentationPlease refer to thedocumentationfor details.For the motivation behind scaper and its applications check out the scaper-paper:Scaper: A library for soundscape synthesis and augmentationJ. Salamon, D. MacConnell, M. Cartwright, P. Li, and J. P. BelloIn IEEE Workshop on Applications of Signal Processing to Audio and Acoustics (WASPAA), New Paltz, NY, USA, Oct. 2017.InstallationNon-python dependenciesScaper has one non-python dependency:FFmpeg:https://ffmpeg.org/If you are installing Scaper on Windows, you will also need:SoX:http://sox.sourceforge.net/On Linux/macOS SoX is replaced bySoxBindingswhich is significantly faster, giving better runtime performance in Scaper. On these platforms SoxBindings is installed automatically when callingpip install scaper(see below).Linux/macOSIf you're usingAnaconda(orminiconda) to manage your python environment (recommended), you can install FFmpeg usingcondaon macOS/Linux:conda install -c conda-forge ffmpegmacOSOn macOS FFmpeg can be installed usinghomebrew:brew install ffmpegLinuxOn linux you can use your distribution's package manager, e.g. on Ubuntu (15.04 "Vivid Vervet" or newer):sudo apt-get install ffmpegNOTE: on earlier versions of Ubuntuffmpeg may point to a Libav binarywhich is not the correct binary. If you are using Anaconda, you can install the correct version as described earlier by callingconda install -c conda-forge ffmpeg. Otherwise, you canobtain a static binary from the ffmpeg website.WindowsOn windows you can use the provided installation binaries:SoX:https://sourceforge.net/projects/sox/files/sox/FFmpeg:https://ffmpeg.org/download.html#build-windowsInstalling ScaperThe simplest way to install scaper is by usingpip, which will also install the required python dependencies if needed. To install scaper using pip, simply run:pip install scaperTo install the latest version of scaper from source, clone or pull the lastest version:git clone git@github.com:justinsalamon/scaper.gitThen enter the source folder and install using pip to handle python dependencies:cd scaper
pip install -e .TutorialTo help you get started with scaper, please see thisstep-by-step tutorial.Exampleimportscaperimportnumpyasnp# OUTPUT FOLDERoutfolder='audio/soundscapes/'# SCAPER SETTINGSfg_folder='audio/soundbank/foreground/'bg_folder='audio/soundbank/background/'n_soundscapes=1000ref_db=-50duration=10.0min_events=1max_events=9event_time_dist='truncnorm'event_time_mean=5.0event_time_std=2.0event_time_min=0.0event_time_max=10.0source_time_dist='const'source_time=0.0event_duration_dist='uniform'event_duration_min=0.5event_duration_max=4.0snr_dist='uniform'snr_min=6snr_max=30pitch_dist='uniform'pitch_min=-3.0pitch_max=3.0time_stretch_dist='uniform'time_stretch_min=0.8time_stretch_max=1.2# Generate 1000 soundscapes using a truncated normal distribution of start timesforninrange(n_soundscapes):print('Generating soundscape:{:d}/{:d}'.format(n+1,n_soundscapes))# create a scapersc=scaper.Scaper(duration,fg_folder,bg_folder)sc.protected_labels=[]sc.ref_db=ref_db# add backgroundsc.add_background(label=('const','noise'),source_file=('choose',[]),source_time=('const',0))# add random number of foreground eventsn_events=np.random.randint(min_events,max_events+1)for_inrange(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))# generateaudiofile=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)How to contributeIf you would like to contribute a feature and/or bugfix to this repository, please follow the following steps:Create an issue describing the feature/fix.I will reply on the issue thread to determine whether the feature/fix can/should be added.Discuss design/implementation details in the issue thread and reach consensus.Once consensus is reached (and only then), start a pull request (PR). Further discsussion can continue in the PR thread.Implement feature/fix, ensuring all current unit tests pass and new tests are added to maintain 100% test coverage. Inline docstrings as well as the main docs files should also be updated accordingly.Request code review once the pull request is ready for review.Fix requested changes to the pull request if any. Repeat steps 5-7 until the PR is approved.once the PR is approved I will merge it into master (and most likely create a new release).IMPORTANT: please be sure to always discuss a proposed feature/fix in an issue before creating a pull request.