Skip to main content

Best Practices

General

  • Ensure that SwitchboardSDK is initialized with the proper credentials before any other component is created.

  • If you encounter issues or crashes, always check the log messages; you may find useful information there.

  • If you plan the use the audio graph input node (microphone), make sure the necessary permissions are granted.

  • Never have more than one AudioEngine running at the same time.

  • If you have an AudioGraph that is run by an AudioEngine and you want to render that AudioGraph to a file using the OfflineGraphRenderer, make sure to stop the AudioEngine first and start it back again once the render is finished. Otherwise, you will hear how the OfflineGraphRenderer is running the AudioGraph, which is usually not desired.

class MyAudioEngine {

let audioEngine = SBAudioEngine()
let audioGraph = SBAudioGraph()
let noiseGeneratorNode = SBWhiteNoiseGeneratorNode()

init() {
audioGraph.addNode(noiseGeneratorNode)
audioGraph.connect(noiseGeneratorNode, to: audioGraph.outputNode)
audioEngine.start(audioGraph)
}

func renderGraph() {
audioEngine.stop()
let offlineGraphRenderer = SBOfflineGraphRenderer()
// setup params like sample rate, etc.
offlineGraphRenderer.processGraph(audioGraph, withOutputFile: "mixedFilePath.wav", withOutputFileCodec: SBCodec.mp3)
audioEngine.start()
}
}

Android

  • Always call close() on SwitchboardSDK components like AudioEngine, AudioGraph, audio nodes, or any other component that has a close method when you no longer need them. For example, if you have an Activity, it's usually a good idea to call close() in the onDestroy() method. This can easily be forgotten if you have local variables on the stack.

fun foo() {
val graphRenderer = OfflineGraphRenderer()
// Render graph
.....

// Don't forget to call close at the end of the function
graphRenderer.close()
}
  • Do not use SwitchboardSDK components after you have called close() on them.