In [17]:
    
import pyrhythmicator
from IPython.display import Audio, display
    
Define the rhythm synthesizer with 3 voices in 4/4:
In [18]:
    
pg = pyrhythmicator.PatternGenerator(4,4,['4n','8n','16n',],
                                     metric_factor=[1.,1.,1.,],
                                     syncopate_factor=[0.,1.,1.,],
                                     density=[0.5,0.5,0.9],
                                     dynamic_range_low=[0.8,0.7,0.7])
    
Generate a 3-voice pattern:
In [19]:
    
pg.generate_pattern(3)
    
    
Synthesize the pattern given the 3 audio files in tests/data. Output the audio to output_file.wav and the annotation file to output_file.jams:
In [20]:
    
mix, voices = pg.synthesize('output_file.wav', 
                            output_jams_file='output_file.jams',
                            audio_files=pyrhythmicator.list_audio_files_in_dir('tests/data', prepend_path=True))
print('Mix:')
display(Audio(mix, rate=pg.sample_rate))
for k, voice in enumerate(voices):
    print('Voice {}:'.format(k))
    display(Audio(voice, rate=pg.sample_rate))
    
    
    
    
    
    
    
    
    
Synthesize another output file, this time with a duration of 9.7 s:
In [21]:
    
mix, voices = pg.synthesize('output_file2.wav', 
                            output_jams_file='output_file2.jams',
                            duration_sec=9.7,
                            audio_files=pyrhythmicator.list_audio_files_in_dir('tests/data', prepend_path=True))
display(Audio(mix, rate=pg.sample_rate))
    
    
Load a pattern generator and pattern from an annotation file, and synthesize again:
In [22]:
    
pg = pyrhythmicator.PatternGenerator.from_jams('output_file2.jams')
mix, voices = pg.synthesize('output_file3.wav')
display(Audio(mix, rate=pg.sample_rate))
    
    
Generate 5 patterns given the current pattern generator:
In [23]:
    
import random
for i in range(5):
    idx = random.randint(0,1000)
    pg.generate_pattern(3)
    mix, voices = pg.synthesize('pattern_{}.wav'.format(idx),
                                output_jams_file='pattern_{}.jams'.format(idx),
                                duration_sec=20.4,
                                audio_files=pyrhythmicator.list_audio_files_in_dir('tests/data',prepend_path=True))
    
    print('Pattern {}:'.format(i))
    display(Audio(mix, rate=pg.sample_rate))
    
    
    
    
    
    
    
    
    
    
    
In [ ]: