Recording
About Audio Recording
Audio recording is the process of capturing sound waves and converting them into a digital or analog format that can be stored and played back. It is an essential part of the music industry, as well as film, television, and radio production.
Code Example
This example can record the user's microphone signal into an audio file using RecorderNode
. The recorded audio file is played back using AudioPlayerNode
.
- JSON
- Swift
- Kotlin
- C++
- JavaScript
{
"nodes": {
{ "id": "recorderNode", "type": "RecorderNode" },
{ "id": "audioPlayerNode", "type": "AudioPlayerNode" }
},
"connections": {
{ "sourceNode": "inputNode", "destinationNode": "recorderNode" },
{ "sourceNode": "audioPlayerNode", "destinationNode": "outputNode" }
},
"tracks": {
"recorderNode": "recording.mp3",
"audioPlayerNode": "recording.mp3"
}
}
import SwitchboardSDK
class RecorderExample {
let audioGraph = SBAudioGraph()
let recorderNode: SBRecorderNode
let audioPlayerNode = SBAudioPlayerNode()
let audioEngine = SBAudioEngine()
var currentFormat: SBCodec = .wav
init() {
recorderNode = SBRecorderNode(
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 RecorderExample(context: Context) {
val audioEngine = AudioEngine(context)
val audioGraph = AudioGraph()
val recorderNode = RecorderNode()
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()
}
}
#include "AudioGraph.hpp"
#include "AudioPlayerNode.hpp"
#include "RecorderNode.hpp"
using namespace switchboard;
class RecorderExample {
public:
RecorderExample() {
// Adding nodes to audio graph
audioGraph.addNode(recorderNode);
audioGraph.addNode(audioPlayerNode);
// Connecting audio nodes
audioGraph.connect(audioGraph.getInputNode(), recorderNode);
audioGraph.connect(audioPlayerNode, audioGraph.getOutputNode());
// Starting the graph
audioGraph.start();
}
void startRecording() {
recorderNode.start();
}
void stopRecording() {
recorderNode.stop("recording.mp3", ::Mp3);
audioPlayerNode.load(recorderNode.getFilePath(), ::Mp3);
}
void startPlayback() {
audioPlayerNode.play();
}
void stopPlayback() {
audioPlayerNode.stop();
}
// Example method called by the audio processing pipeline on each buffer
bool process(float** buffers, const uint numberOfChannels, const uint numberOfFrames, const uint sampleRate) {
AudioBuffer<float> inBuffer = AudioBuffer<float>(numberOfChannels, numberOfFrames, false, sampleRate, buffers);
AudioBuffer<float> outBuffer = AudioBuffer<float>(numberOfChannels, numberOfFrames, false, sampleRate, buffers);
const bool result = audioGraph->processBuffer(&inBuffer, &outBuffer);
return result;
}
private:
AudioGraph audioGraph;
RecorderNode recorderNode;
AudioPlayerNode audioPlayerNode;
};
Coming soon...