Skip to main content
Version: 5.5

Audio hooking

PlanetKit provides the audio hooking function, which allows you to get the audio data before Planet Cloud transmits audio to a peer. This function can be used to modify the local user's voice or use the audio data for speech recognition.

Supported call typeMinimum SDK version
1-to-1 call5.5

Overview

The PlanetKitCall class provides methods to use the audio hooking function.

Enable audio hooking

To enable audio hooking, call enableHookMyAudio() with the implementation of PlanetKitCallHookedAudioDelegate.

When audio hooking is enabled, you can receive a PlanetKitHookedAudio object through the didHook event.

Modify audio data (Optional)

To modify the hooked audio data, set data of PlanetKitHookedAudio with another Data object.

Note

In the PlanetKitHookedAudio class, only the raw audio data (data) can be modified, and metadata such as channel, sampleCount, sampleRate, sampleType, and seq cannot be changed. When you modify data, make sure that the format represented by the metadata is maintained.

Put back the audio data

To put the hooked audio back for transmission, call putHookedMyAudioBack() with a PlanetKitHookedAudio object.

Warning

After enabling audio hooking, you must put back the audio regardless of whether the audio data has been modified. Otherwise, audio is not transmitted to the peer.

Disable audio hooking

To disable audio hooking, call disableHookMyAudio().

Sample code

The following sample code shows how to use the audio hooking function for voice modification.

// Get instance of PlanetKitCall
var call: PlanetKitCall?

// Implement audio modifier with PlanetKitCallHookedAudioDelegate
class HookedAudioModifier: PlanetKitCallHookedAudioDelegate {
func didHook(_ call: PlanetKitCall, audio: PlanetKitHookedAudio) {
// process `audio.data` as necessary

if !call.putHookedMyAudioBack(audio: audio) {
NSLog("putHookedMyAudioBack returned false")
}
}
}

// HookedAudioModifier object
let modifier = HookedAudioModifier()

// Method to enable audio hook
func enableAudioHook(call: PlanetKitCall, modifier: HookedAudioModifier) {
call.enableHookMyAudio(delegate: modifier) { success in
if success {
NSLog("Audio hook enabled successfully")
} else {
NSLog("Failed to enable audio hook")
}
}
}

// Method to disable the audio hook
func disableAudioHook(call: PlanetKitCall) {
call.disableHookMyAudio() { success in
if success {
NSLog("Audio hook disabled successfully")
} else {
NSLog("Failed to disable audio hook")
}
}
}

APIs related to audio hooking are as follows.

Classes/protocols

Methods/properties

Events