Last active
March 1, 2020 20:13
-
-
Save pseeth/d8140c9c0a649d6ad0b2b72ee3069b6d to your computer and use it in GitHub Desktop.
Self-contained tutorial for Scaper w/ downloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to install requirements | |
# conda install -c conda-forge sox ffmpeg | |
# OR | |
# brew install sox | |
# brew install ffmpeg | |
# OR | |
# sudo apt-get install sox | |
# sudo apt-get install ffmpeg | |
# THEN | |
# pip install scaper | |
import scaper | |
import os | |
import zipfile | |
import subprocess | |
# Download the audio automatically | |
url = "https://github.com/justinsalamon/scaper/archive/v1.2.0.zip" | |
if not os.path.exists('audio'): | |
subprocess.run(f'wget {url}', shell=True) | |
subprocess.run(f'unzip v1.2.0.zip', shell=True) | |
os.makedirs('audio/', exist_ok=True) | |
subprocess.run(f'cp -r scaper-1.2.0/tests/data/audio .', shell=True) | |
subprocess.run(f'rm -rf scaper-1.2.0/', shell=True) | |
subprocess.run(f'rm -rf v1.2.0.zip', shell=True) | |
path_to_audio = 'audio/' | |
soundscape_duration = 10.0 | |
seed = 123 | |
foreground_folder = os.path.join(path_to_audio, 'foreground') | |
background_folder = os.path.join(path_to_audio, 'background') | |
sc = scaper.Scaper(soundscape_duration, foreground_folder, background_folder, | |
random_state=seed) | |
sc.ref_db = -20 | |
sc.add_background(label=('const', 'park'), | |
source_file=('choose', []), | |
source_time=('const', 0)) | |
sc.add_event(label=('const', 'siren'), | |
source_file=('choose', []), | |
source_time=('const', 0), | |
event_time=('uniform', 0, 9), | |
event_duration=('truncnorm', 3, 1, 0.5, 5), | |
snr=('normal', 10, 3), | |
pitch_shift=('uniform', -2, 2), | |
time_stretch=('uniform', 0.8, 1.2)) | |
for _ in range(2): | |
sc.add_event(label=('choose', []), | |
source_file=('choose', []), | |
source_time=('const', 0), | |
event_time=('uniform', 0, 9), | |
event_duration=('truncnorm', 3, 1, 0.5, 5), | |
snr=('normal', 10, 3), | |
pitch_shift=None, | |
time_stretch=None) | |
audiofile = 'soundscape.wav' | |
jamsfile = 'soundscape.jams' | |
txtfile = 'soundscape.txt' | |
sc.generate(audiofile, jamsfile, | |
allow_repeated_label=True, | |
allow_repeated_source=True, | |
reverb=None, | |
disable_sox_warnings=True, | |
no_audio=False, | |
txt_path=txtfile, | |
save_isolated_events=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment