LinkVisual SDK for Android allows you to implement the voice intercom feature. This topic describes how to implement this feature.
For convenience purposes, all mentions of LinkVisual SDK in this topic refer to LinkVisual SDK for Android.
Prerequisites
A product and device are created in the IoT Platform console. For more information, see Device Connection.
LinkVisual SDK is obtained. For more information, see Obtain the SDK.
LinkVisual SDK is initialized. For more information, see Initialize the SDK.
Audio coding standards
Voice intercom supports G711a, G711u, and Advanced Audio Coding Low Complexity (AAC-LC) codecs. These coding standards have the following characteristics:
Before you select a codec, you must check whether your IP camera supports the codec.
Support the sample rates of 8 kHz and 16 kHz.
Support encoding.
Support decoding.
Voice intercom modes
The following table describes the voice intercom modes and usage notes.
Mode | Description | Usage notes |
One-way voice intercom | The app collects and sends audio data to the IP camera for playback. | The mobile phone must remain silent when the app collects audio data. |
Two-way voice intercom | Both the app and IP camera collect and play audio simultaneously. | The IP camera must support Acoustic Echo Cancellation (AEC). Otherwise, we do not recommend that you use this function. |
Procedure
After the server sends the command to start stream ingest, perform the following operations:
Use the
OnLiveIntercomListener
listener that you registered to notify the IP camera of events, such as starting voice intercom, stopping voice intercom, receiving audio parameters, and receiving audio data.Use a listener to listen to errors that occur in stream ingest, and notify the app.
ImportantDo not block callbacks.
Implementation process:
Select a voice intercom mode.
// Select the two-way voice intercom mode. IPCDev.getInstance().setLiveIntercomModeBeforeInit(IPCLiveIntercomV2.LiveIntercomMode.DoubleTalk);
Configure listeners.
// Configure a listener for voice intercom events. IPCDev.getInstance().getIpcLiveIntercom().setOnLiveIntercomListener(MainActivity.this); // Configure a listener for callback errors in voice intercom. IPCDev.getInstance().getIpcLiveIntercom().setOnLiveIntercomErrorListener(MainActivity.this);
Sample code
You can use the following sample code to register an event listener and an error listener.
public interface OnLiveIntercomListener {
/**
* Receive a request from the app for starting voice intercom.
*
* @return: Return the format of upstream audio parameters used by the IP camera, such as the sample rate, number of channels, bit width, and audio format. Make sure that the app supports these audio parameter settings.
*/
AudioParams onStartVoiceIntercom();
/**
* Receive the request to stop voice intercom.
*/
void onStopVoiceIntercom();
/**
* Receive audio parameters from the app, which indicates that the channel with the app has been established and voice intercom can start.
* @param audioParams: The audio parameters from the app.
*/
void onAudioParamsChange(AudioParams audioParams);
/**
* Receive Pulse-Code Modulation (PCM) data from the app, which is often used for UI display, such as the volume.
* @param buffer
* @param size
*/
void onAudioBufferReceive(byte[] buffer, int size);
}
public interface OnLiveIntercomErrorListener{
/**
* An error occurs in voice intercom.
* @param error: See {@link LiveIntercomError}.
*/
void onError(LiveIntercomError error);
}
Error codes
Error code | Description | Solution |
LiveIntercomError.INVALID_AUDIO_PARAMS | Invalid audio parameters of the IP camera. | Check the following items. Try again after the following requirements are met.
|
LiveIntercomError.CONNECTION_STREAM_FAILED | Failed to establish a voice intercom channel. | Make sure that the network connection is normal and try again. |
LiveIntercomError.SEND_STREAM_DATA_FAILED | Failed to send the audio data. | This error occurs when the network connection is interrupted or the voice intercom is disabled by the peer. You can ignore the error. |
LiveIntercomError.INIT_RECORD_FAILED | Failed to initialize the recorder. | Check whether any of the following exceptions occurs. Fix the issue and try again.
|
LiveIntercomError.START_RECORD_FAILED | Failed to start the recorder. | Check whether another app is using the recorder. If it is, terminate the ongoing process and try again. |
LiveIntercomError.READ_RECORD_BUFFER_FAILED | Failed to obtain data from the recorder. | An exception occurs on the recorder. Restart the IP camera and try again. |
LiveIntercomError.INIT_AUDIO_PLAYER_FAILED | Failed to create an audio player. | An exception occurs on the audio player. Restart the IP camera and try again. |