Skip to main content

Advance

Custom audio parameters

You can use custom audio parameters in your app using builder pattern. Instead of directly using

VoicePing.init(this, "voiceping_sdk_server_url")

to initialize VoicePing, you can use,

val audioParam = AudioParam.Builder()
.setUsingOpusCodec(true)
.setSampleRate(16000)
.setFrameSize(960)
.setChannelSize(1)
.build()
VoicePing.init(this, "voiceping_sdk_server_url", audioParam)

Intercepting audio data

AudioInterceptor

Intercepting audio data

The audio data are represented in array of byte. There are 4 states that are exposed to client app so that the client app will be able to intercept audio data and do some advance techniques to them.

Before being encoded (raw audio data)

audioRecorder.setInterceptorBeforeEncoded(audioInterceptor);

This state is suitable for doing some advance techniques that require raw recorded audio data, such as showing amplitude of the audio, change pitch, etc.

After being encoded (encoded audio data)

audioRecorder.setInterceptorAfterEncoded(audioInterceptor);

If you want to modify audio data after the data being encoded but before being sent to the server, you can intercept data in this state. Operation such as encryption that doesn't require raw data is suitable in this state.

Before being decoded (encoded audio data)

audioReceiver.setInterceptorBeforeDecoded(audioInterceptor);

Let's say, you have encrypted audio data in previous state, and you want to decrypt them, you can use this state to do that.

After being decoded (raw audio data)

audioReceiver.setInterceptorAfterDecoded(audioInterceptor);

If you want to do some advance techniques that require raw received audio data, such as showing amplitude of the audio, change pitch, etc, then this state is for you.

OutgoingTalkListener

To do some advance techniques for the recorded audio, such as showing amplitude of the audio, change pitch, and save the audio to local storage, you need to implement OutgoingTalkListener and attach it to startTalking. OutgoingTalkListener is needed to do startTalking,

VoicePing.startTalking("receiver_id", ChannelType.PRIVATE, this)

with this is the instance that has implemented OutgoingTalkListener.

class MainActivity : AppCompatActivity(), OutgoingTalkCallback {

/**
* Other class code
*/

override fun onOutgoingTalkStarted(audioRecorder: AudioRecorder) {
// Do something after invoking startTalking.
}

override fun onOutgoingTalkStopped(isTooShort: Boolean, isTooLong: Boolean) {
// Do something after invoking stopTalking.
}

override fun onDownloadUrlReceived(downloadUrl: String) {
// Do something after download URL received
}

override fun onOutgoingTalkError(e: VoicePingException) {
// Do something on outgoing talk error.
}
}

You can do a lot of thing by putting your code inside the appropriate methods.

IncomingTalkListener

To do some advance techniques for the received audio, you need to implement IncomingTalkListener. IncomingTalkListener is needed to customize incoming talk.

class MainActivity : AppCompatActivity(), IncomingTalkListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
VoicePing.setIncomingTalkListener(this)
}

// IncomingTalkListener
override fun onIncomingTalkStarted(
audioReceiver: AudioReceiver,
activeChannels: List<Channel>
) {
// Do something after incoming talk started.
}

override fun onIncomingTalkStopped(
audioMetaData: AudioMetaData,
activeChannels: List<Channel>
) {
// Do something after incoming talk stopped.
}

override fun onIncomingTalkError(e: VoicePingException) {
// Do something on error.
}
}

Warning

AudioInterceptor is running on separated thread from Main Thread. If you want to touch UI from there, you need to run it on Main Thread.