Recorder
This example can record the user's microphone signal into an audio file using RecorderNode
. The recorded audio file is played back using AudioPlayerNode
.
- Swift
- Kotlin
import SwitchboardSDK
class RecorderExample {
let audioGraph = SBAudioGraph()
let recorderNode: SBRecorderNode
let audioPlayerNode = SBAudioPlayerNode()
let audioEngine = SBAudioEngine()
var currentFormat: SBCodec = .wav
init() {
recorderNode = SBRecorderNode(
name: "TestRecorderNode",
recordingSampleRate: 48000,
numberOfRecordedChannels: 2
)
audioGraph.addNode(recorderNode)
audioGraph.addNode(audioPlayerNode)
audioGraph.connect(audioGraph.inputNode, to: recorderNode)
audioGraph.connect(audioPlayerNode, to: audioGraph.outputNode)
audioEngine.microphoneEnabled = true
audioEngine.start(audioGraph)
}
func startRecording() {
recorderNode.start()
}
func stopRecording() {
recorderNode.stop("fileName", withFormat: currentFormat)
audioPlayerNode.load(recorderNode.getFilePath(), withFormat: currentFormat)
}
func startPlayback() {
audioPlayerNode.play()
}
func stopPlayback() {
audioPlayerNode.stop()
}
}
import com.synervoz.switchboard.sdk.AudioEngine
import com.synervoz.switchboard.sdk.Codec
import com.synervoz.switchboard.sdk.audioengine.AudioEngine
import com.synervoz.switchboard.sdk.audiograph.AudioGraph
import com.synervoz.switchboard.sdk.audiographnodes.AudioPlayerNode
import com.synervoz.switchboard.sdk.audiographnodes.RecorderNode
class SineWaveGeneratorExample {
val audioEngine = AudioEngine()
val audioGraph = AudioGraph()
val recorderNode = RecorderNode("TestRecorderNode")
val audioPlayerNode = AudioPlayerNode()
init {
audioGraph.addNode(recorderNode)
audioGraph.addNode(audioPlayerNode)
audioGraph.connect(audioGraph.inputNode, recorderNode)
audioGraph.connect(audioPlayerNode, audioGraph.outputNode)
audioEngine.start(audioGraph)
}
fun startRecording() {
recorderNode.start()
}
fun stopRecording() {
recorderNode.stop("fileName", currentFormat)
audioPlayerNode.load(recorderNode.getFilePath(), currentFormat)
}
fun startPlayback() {
audioPlayerNode.play()
}
fun stopPlayback() {
audioPlayerNode.stop()
}
}