ianhi / birdsongs

Model implemention of motor gestures to create synthetic birdsongs

Home Page:https://saguileran.github.io/birdsongs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

drawing

birdsongs

A python package to analyze, visualize and create synthetic syllables.

Binder

Table of Contents


Installation

Requirments

syllables is implemented in python 3.8: It requires:

  • numpy
  • matplotlib
  • scipy
  • peakutils
  • lmfit
  • librosa
  • scikit-maad
  • sympy
  • pandas
  • sklearn
  • IPython
  • mpl_interactions
  • mpl_point_clicker

Downloading

In order to use birdsongs, clone the repository and enter to the folder repository

git clone https://github.com/saguileran/birdsongs.git
cd birdsongs

you can verify the current branch with the command git branch -a. You have to be in main branch, to change the branch use the command git checkout main.

The next step is to install the required packages, any of the following commands line will work

pip install -r ./requirements.txt
python -m pip install -r ./requirements.txt
cd birdsongs

the last step is to enter at the birdsongs folder to use its function with the examples audios.

Use

Define objects

Import the package as bs

import birdsongs as bs
from birdsongs.utils import * 

define a ploter and paths objects, optionally you can specify the audio folder or not

# audios = "path\to\audios"
# root = "path\to\audios"
# bird_name = "path\to\audios"

ploter = bs.Ploter()  # save = True to save the figures
paths  = bs.Paths()   # root, audios_path, bird_name

define and plot the audio birdsong

bird = bs.Song(paths, no_file=3) # tlim=(t0,tend) you can also give a time interval or frequency limits flim=(f0,fmax)
ploter.Plot(bird)

you can also define the time intervals of interest from the whole song with the commands

klicker = ploter.FindTimes(bird) # FF_on=True enables fundamental frequency plot
plt.show()

after close the matplotlib windows run

time_intervals = Positions(klicker)

The final step is to define the optimizer object to generate the synthetic syllable (song).

syllable  = bs.Syllable(bird)               # you can also give a time or frequency interval flim=(fmin,fmax), tlim=(t0,tend)

brute     = {'method':'brute', 'Ns':11}     # optimization method and its parameters
optimizer = bs.Optimizer(syllable, brute)   # define optimizer to the syllable object

optimizer.optimal_gamma                     # find teh optimal gamma over the whole bird syllables
optimizer.OptimalParams(obj, Ns=11)         # find optimal alpha and beta parameters
    
Display(obj.p)                              # display optimal problem parameters
obj_synth_optimal = obj.Solve(obj.p)        # generate the synthetic syllable with the optimal parameters set
    
ploter.Syllables(obj, obj_synth_optimal)    # plot real and synthetic songs, sound waves and spectrograms
ploter.PlotAlphaBeta(obj_synth_optimal)     # plot alpha and beta parameters in function of time (just syllable has this attributes)
ploter.Result(obj, obj_synth_optimal)       # plot the spectrograms, scores and features of both objects, the real and synthetic
    
bird.WriteAudio();  synth_bird.WriteAudio() # write both objects, real and synthetic

other available option is to split the audio with the time intervals define and find the synthetic song

brute          = {'method':'brute', 'Ns':11}
optimizer_bird = bs.Optimizer(bird, method_kwargs=brute)
synth_bird     = optimizer_bird.SongByTimes(time_intervals)

to visualize and write audio

ploter.Plot(synth_bird)
bird.WriteAudio();  synth_bird.WriteAudio()

The repository has some audio examples, in examples/audios folder. You can download and store your own audios in the same folder, the audios must be in WAV format or birdosngs will not import them, we suggest use audacity to convert the audios.

Overview

Objective

Design, development, and evaluation of a physical model for generating synthetic birdsongs from recorded birdsongs

Repository Contents

This repository have the documentation, scripts, and results delelop to achive the proposed objective.

The model used, Motor Gestures [1], have been developed by profesog G. Mindlin at the Dynamical Systems Laboratory (in spanish LSD) of the university of Buenos Aires, Argentina.

Physical Model

Schematic visualization of the complete Motod Gestures model: syrinx, trachea, glotis, and OEC.

Programming Object Oriented (POO)

Taking advantege of the POO programming paradig, to avoid repeat long codes execution and easy reproducibility, five objects ared created:

  • Syllable: define a object from audio syllable with its tempo and spectral features
  • Optimizer: define a object to optimize function from method and syllables
  • Song: define a object to read and split an audio song in syllables
  • Plot: define a object to plot real and synthec syllables or songs
  • Paths: define a object to organize folders location

In order to understand the diagram methodology, the following icons will be used.

methodology

Implementation

Using the previous objects defined, the optimization problem is solved by following the next diagram

methodology

Results

References

Literature

[1] Amador, A., Perl, Y. S., Mindlin, G. B., & Margoliash, D. (2013). Elemental gesture dynamics are encoded by song premotor cortical neurons. Nature 2013 495:7439, 495(7439), 59–64. https://doi.org/10.1038/nature11967

Software

[2] Newville, M., Stensitzki, T., Allen, D. B., & Ingargiola, A. (2014). LMFIT: Non-Linear Least-Square Minimization and Curve-Fitting for Python. https://doi.org/10.5281/ZENODO.11813

[3] Ulloa, J. S., Haupert, S., Latorre, J. F., Aubin, T., & Sueur, J. (2021). scikit-maad: An open-source and modular toolbox for quantitative soundscape analysis in Python. Methods in Ecology and Evolution, 12(12), 2334–2340. https://doi.org/10.1111/2041-210X.13711

[4] McFee, B., Raffel, C., Liang, D., Ellis, D. P., McVicar, M., Battenberg, E., & Nieto, O. & (2015). librosa: Audio and music signal analysis in python. In Proceedings of the 14th python in science conference , 12(12), (Vol. 8). https://librosa.org/doc/latest/index.html

Audios Dataset

[5] Xeno-canto Foundation and Naturalis Biodiversity Center & (2005). xeno-canto: https://xeno-canto.org/ Sharing bird sounds from around the world. Dissertation Audios Dataset https://xeno-canto.org/set/8103
[6] Ther Cornell Lab of Ornithology & (2005). ebird , https://ebird.org/

About

Model implemention of motor gestures to create synthetic birdsongs

https://saguileran.github.io/birdsongs/

License:GNU General Public License v3.0


Languages

Language:Jupyter Notebook 99.4%Language:Python 0.5%Language:TeX 0.1%