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.
- Swift
- Kotlin
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()
}
}
class MyAudioEngine(context: Context) {
val audioEngine = AudioEngine(context)
val audioGraph = AudioGraph()
val noiseGeneratorNode = WhiteNoiseGeneratorNode()
init {
audioGraph.addNode(noiseGeneratorNode)
audioGraph.connect(noiseGeneratorNode, audioGraph.outputNode)
audioEngine.start(audioGraph)
}
func renderGraph() {
audioEngine.stop()
let offlineGraphRenderer = SBOfflineGraphRenderer()
// setup params like sample rate, etc.
offlineGraphRenderer.processGraph(audioGraph, "mixedFilePath.wav", Codec.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 callclose()
in theonDestroy()
method. This can easily be forgotten if you have local variables on the stack.
- Kotlin
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. -
If you encounter the error
No implementation found for void com.synervoz.* ... is the library loaded, e.g. System.loadLibrary?
, it likely indicates that you attempted to use a Switchboard SDK component, such as an audio node, before initializing the SDK. To prevent this, ensure that the SDK is initialized in theonCreate
method of your main application class, which extendsApplication()
. Check the Integration guide for more information.