Skip to content

Scheduler

NRT

Class for handling non-realtime (NRT) processing in MMMAudio. This class provides a static method to save audio output to a WAV file while processing events from a json score file.

save_to_wav(mmm_audio, filename, duration_seconds=200, score_path=None, targets=None, verbose=False) staticmethod

Save audio output to a WAV file while processing events from a json score file.

Parameters:

Name Type Description Default
mmm_audio MMMAudio

The MMMAudio instance to get audio samples from. Do not call mmm_audio.start_audio() before calling this function, as sample allocation will be handled internally.

required
filename

The name of the output WAV file.

required
duration_seconds

The duration of the output audio in seconds.

200
score_path

Optional path to a json score file containing events to process during audio generation.

None
targets

Optional dictionary mapping object names to their corresponding instances for event processing. Usually this will be a dictionary of MMMAudio instances and PolyPal instances.

None
verbose

If True, print progress and event processing information.

False

Scheduler

The main Scheduler class for the Python side of MMMAudio. Can be used to run asyncio coroutines in a separate scheduling thread. This has the advantage of not blocking the main thread, but also allows for each schedule to be cancelled individually.

__init__()

Initialize the Scheduler. Also starts the asyncio event loop in its own unique thread.

get_routs()

Get all running routine.

sched(coro)

Add a coroutine to the running event loop.

Parameters:

Name Type Description Default
coro

The coroutine to be scheduled.

required

Returns:

Type Description

The Future object representing the scheduled coroutine. This returned object can be used to check the status of the coroutine, retrieve its result, or stop the coroutine when needed.

start_thread()

Create a new asyncio event loop and run it in a separate scheduling thread.

stop_routs()

Stop all running routines.

stop_thread()

Stop the asyncio event loop and thread and start a new one.

tc_sleep(delay, result=None) async

Coroutine that completes after a given time (in seconds).

Parameters:

Name Type Description Default
delay

Time in seconds to wait before completing the coroutine.

required
result

Optional result to return when the coroutine completes.

None