A python package to analyze, visualize and create synthetic syllables.
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
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.
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.
Design, development, and evaluation of a physical model for generating synthetic birdsongs from recorded birdsongs
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.
Schematic visualization of the complete Motod Gestures model: syrinx, trachea, glotis, and OEC.
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.
Using the previous objects defined, the optimization problem is solved by following the next diagram