Skip to main content

Kotlin / Java API

For JVM-based systems (Android, server-side JVM), the SDK exposes the same v3 call surface through the com.synervoz.switchboard.sdk.Switchboard singleton.

Every Switchboard object — the SDK singleton ("switchboard"), engines, nodes, extensions — is identified by an object ID. The same handful of calls drives every object.

All calls return a SwitchboardResult<T> with isSuccess, value, and error. Snippets below assume import com.synervoz.switchboard.sdk.Switchboard.

Initialize SDK

Two overloads — one takes appID/appSecret directly, one takes a full config map.

fun initialize(context: Context, appId: String, appSecret: String,
extensions: Map<String, Any> = emptyMap()): SwitchboardResult<Unit>
fun initialize(context: Context, config: Map<String, Any>): SwitchboardResult<Unit>
val result = Switchboard.initialize(context, "your-app-id", "your-app-secret")
if (result.isError) {
Log.e("SB", result.error ?: "unknown error")
}

Deinitialize SDK

There's no dedicated deinitialize wrapper on Kotlin yet; if you need it, invoke it via callAction:

Switchboard.callAction("switchboard", "deinitialize")

Create Engine

Creates an engine from a config map (or JSON string). Returns the engine's ObjectID.

fun createEngine(config: Map<String, Any>): SwitchboardResult<ObjectID>
fun createEngine(configJson: String): SwitchboardResult<ObjectID>
val createResult = Switchboard.createEngine(engineConfig)
if (createResult.isError) { /* handle */ }
val engineID = createResult.value!!

Destroy Engine

Not exposed directly on Kotlin yet — invoke through callAction on the SDK singleton:

Switchboard.callAction("switchboard", "destroyEngine", mapOf("engineID" to engineID))

Call Action

Invokes a named action on any Switchboard object.

fun callAction(
objectId: ObjectID,
actionName: String,
params: Map<String, Any> = emptyMap()
): SwitchboardResult<String>
// Start the engine
Switchboard.callAction(engineID, "start")

// Load a file into a player node
Switchboard.callAction("playerNode", "load", mapOf(
"audioFilePath" to "AudioFiles/speech-mono-48k.wav"
))

Set Value

Writes a value to a key on a Switchboard object.

fun setValue(objectId: ObjectID, key: String, value: Any): SwitchboardResult<Unit>
Switchboard.setValue("playerNode", "isLoopingEnabled", true)
Switchboard.setValue("gainNode", "gain", 0.5)

Get Value

Reads a value from a key on a Switchboard object.

fun getValue(objectId: ObjectID, key: String): SwitchboardResult<Any?>
val framesResult = Switchboard.getValue("recorderNode", "framesRecorded")
if (framesResult.isSuccess) {
val frames = framesResult.value
// ...
}

Add Event Listener

Subscribes to a named event. Two overloads — one takes a SwitchboardEventCallback, one takes a lambda (eventName, eventData) -> Unit. Returns a ListenerID.

fun addEventListener(
objectId: ObjectID,
eventName: String,
callback: (eventName: String, eventData: Any?) -> Unit
): SwitchboardResult<ListenerID>
val listenerResult = Switchboard.addEventListener("playerNode", "playbackProgress") { name, data ->
// ...
}
val listenerID = listenerResult.value!!

Remove Event Listener

Unsubscribes a previously registered listener.

fun removeEventListener(objectId: ObjectID, callbackId: ListenerID): SwitchboardResult<Unit>
Switchboard.removeEventListener("playerNode", listenerID)

Full Reference

Open Kotlin / Java API Reference — every class and method.