音景合成与增强库
scaper的Python项目详细描述
替罪羊
音景合成与增强库
详情请参阅documentation
有关scaper及其应用程序背后的动机,请参阅scaper论文:
Scaper: A library for soundscape synthesis and augmentation
J.Salamon、D.MacConnell、M.Cartwright、P.Li和J.P.Bello
2017年10月,在美国纽约新帕茨召开的“信号处理在音频和声学中的应用”IEEE研讨会上。
安装
非python依赖项
scaper有两个非python依赖项:
Linux/macOS
如果使用Anaconda(或miniconda)来管理python环境(推荐),则可以在macos/linux上使用conda
安装这些依赖项:
conda install -c conda-forge sox ffmpeg
Mac操作系统
在macos上,可以使用homebrew:
brew install sox
brew install ffmpeg
Linux
在linux上,您可以使用发行版的包管理器,例如在Ubuntu(15.04“Vivid Vervet”或更新版本)上:
sudo apt-get install sox
sudo apt-get install ffmpeg
注意:在ubuntuffmpeg may point to a Libav binary的早期版本中,它不是正确的二进制文件。如果您使用的是Anaconda,则可以通过调用conda install -c conda-forge ffmpeg
安装前面描述的正确版本否则,您可以obtain a static binary from the ffmpeg website。
窗口
在Windows上,您可以使用提供的安装二进制文件:
- SoX:https://sourceforge.net/projects/sox/files/sox/
- FFmpeg:https://ffmpeg.org/download.html#build-windows
安装scaper
安装scaper的最简单方法是使用pip
,如果需要,它还将安装所需的python依赖项要使用pip安装scaper,只需运行:
pip install scaper
要从源安装最新版本的scaper,请克隆或拉取最新版本:
git clone git@github.com:justinsalamon/scaper.git
然后输入源文件夹并使用pip安装以处理python依赖项:
cd scaper
pip install -e .
教程
为了帮助您开始使用scaper,请参见step-by-step tutorial。
示例
importscaperimportnumpyasnp# 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)