Voice Changer App
About Voice Changer App
In this example we can look at how we can build a voice changer application from Switchboard SDK components.
We need to create an AudioGraph
with an effect to change the voice. For a chipmunk or a deep voice effect, you can use Superpowered's PitchShift
effect, which is available for you as a node, so you can easily put it in your process chain without having to do any low-level development.
Also lets have an echo effect in the chain to get a sound, like if you were standing inside a large cave.
You can use all the effects in a chain one after an other, enabling the ones you need at the time. Disabled effects acts as a passthrough node (no change between input and output).
To check the list of other effects please visit our Superpowered extension page.
You can hear the result live on your output device if you connect it as shown in the example.
This example uses the Superpowered Extension.
Why use the Superpowered Extension instead of Superpowered directly?
Code Example
- Swift
- Kotlin
import SwitchboardSDK
import SwitchboardSuperpowered
class VoiceChangerExample {
let audioGraph = SBAudioGraph()
let pitchShiftNode = SBPitchShiftNode()
let echoNode = SBEchoNode()
let audioEngine = SBAudioEngine()
init() {
audioGraph.addNode(pitchShiftNode)
audioGraph.connect(audioGraph.inputNode, to: pitchShiftNode)
audioGraph.connect(pitchShiftNode, to: echoNode)
audioGraph.connect(echoNode, to: audioGraph.outputNode)
audioEngine.microphoneEnabled = true;
audioEngine.start(audioGraph)
}
func enableChipmunkVoice() {
disableVoiceChanger()
// Raise voice pitch by an octave
pitchShiftNode.isEnabled = true
pitchShiftNode.pitchShiftCents = 1200
}
func enableDeepVoice() {
disableVoiceChanger()
// Lower voice pitch by an octave
pitchShiftNode.isEnabled = true
pitchShiftNode.pitchShiftCents = -1200
}
func enableCaveEffect() {
disableVoiceChanger()
// Turn on echo node
echoNode.isEnabled = true
}
func disableVoiceChanger() {
// Turn of all effects
pitchShiftNode.isEnabled = false
echoNode.isEnabled = false
}
}
import com.synervoz.switchboard.sdk.audioengine.AudioEngine
import com.synervoz.switchboard.sdk.audiograph.AudioGraph
import com.synervoz.switchboardsuperpowered.audiographnodes.PitchShiftNode
import com.synervoz.switchboardsuperpowered.audiographnodes.EchoNode
class VoiceChanger(context: Context) {
val audioEngine = AudioEngine(context)
val pitchShiftNode = PitchShiftNode()
val echoNode = EchoNode()
val audioGraph = AudioGraph()
init {
audioGraph.addNode(pitchShiftNode)
audioGraph.connect(audioGraph.inputNode, pitchShiftNode)
audioGraph.connect(pitchShiftNode, echoNode)
audioGraph.connect(echoNode, audioGraph.outputNode)
audioEngine.enableMicrophone(true)
audioEngine.start(audioGraph)
}
fun enableChipmunkVoice() {
disableVoiceChanger()
// Raise voice pitch by an octave
pitchShiftNode.isEnabled = true
pitchShiftNode.pitchShiftCents = 1200
}
fun enableDeepVoice() {
disableVoiceChanger()
// Lower voice pitch by an octave
pitchShiftNode.isEnabled = true
pitchShiftNode.pitchShiftCents = -1200
}
fun enableCaveEffect() {
disableVoiceChanger()
// Turn on echo node
echoNode.isEnabled = true
}
fun disableVoiceChanger() {
// Turn of all effects
pitchShiftNode.isEnabled = false
echoNode.isEnabled = false
}
}