Skip to main content

Switchboard Objects

The Switchboard SDK is a powerful tool for building and managing audio processing engines. It allows developers to design complex audio workflows using simple JSON configurations, enabling rapid prototyping and deployment. Once the audio engine is set up, its state can be dynamically modified with just a few API calls, providing flexibility and control for real-time audio applications.

In the Switchboard API, everything is a Switchboard Object:

Object TypeDescription
SDK InstanceThe main entry point for interacting with the Switchboard SDK.
EngineAudio processing engine that can run graphs.
GraphManaging and connecting nodes together.
NodesIndividual components within the graph that perform specific tasks.

Switchboard objects share a common behavior model that includes:

FeatureDescription
ConfigurationUsed to create the object and may sometimes be immutable after creation.
ValuesAttributes of the object that can be either read-only or read-write.
ActionsFunctions that you can invoke to perform specific operations on the object.
EventsNotifications that you can subscribe to, allowing you to react to changes or actions.

Creating and Destroying Objects

To work with Switchboard Objects, you typically create and destroy them using provided API methods.

// Creating an object
auto createResult = Switchboard::createEngine(engineConfig);
// Destroying an object
auto destroyResult = Switchboard::destroyObject(objectID);

Read-write values, which can be configured through the provided configuration parameters. These parameters allow you to define the initial state of the object and specify attributes that can be dynamically updated during runtime.

Getting and Setting Values

Switchboard Objects have attributes called Values that can be either read-only or read-write. You can retrieve or modify these values using the provided API methods.

// Getting a value
auto volume = Switchboard::getValue("gainNode", "gain");

// Setting a value
auto setResult = Switchboard::setValue("gainNode", "gain", 0.8);

Values allow you to configure and query the state of objects dynamically, enabling flexible control over your audio processing pipeline.

Calling Actions

Switchboard Objects support Actions, which are functions you can invoke to perform specific operations. Actions allow you to trigger behaviors or processes on an object dynamically.

// Calling an action
auto result = Switchboard::callAction("ttsNode", "synthesize", { { "text", text } });

In the example above, the callAction method is used to invoke the synthesize action on a Text-to-Speech (TTS) node, passing the required parameters as a key-value map. This enables you to interact with objects in a flexible and extensible way.

Subscribing to Events

Switchboard Objects emit Events that you can subscribe to in order to react to changes or specific actions. Events provide a mechanism for asynchronous communication, enabling you to handle updates dynamically.

// Subscribing to an event
Switchboard::addEventListener("sttNode", "transcription", [](const std::any& data) {
const auto text = std::any_cast<std::string>(data);
std::cout << "STT node transcribed: " << text << std::endl;
});

// Unsubscribing from an event
Switchboard::removeEventListener("sttNode", "transcription");

In the example above, the addEventListener method is used to subscribe to the transcription event on a Speech-to-Text (STT) node. The callback function processes the event data, allowing you to handle the transcription results. To stop receiving updates, you can use the removeEventListener method.