The real-time caption feature from DingRTC provides a speech-to-text service for scenarios such as online meetings and online education. It helps participants better understand meeting content. This topic describes how to integrate this feature on Android.
Integration guide
Integrate SDK version 3.8.0 or later.
Implement basic caption features
1. Before you use the caption feature on an Android client, integrate the Smart Summary feature on your application server. Then, start the feature by calling the StartCloudNote interface.
2. Follow the instructions in the "Quick Start" section to create an engine, join a channel, and publish and subscribe to audio and video streams.
3. Obtain the caption manager.
DingRtcEngineSubtitleManager subtitleManager = mRtcEngine.getSubtitleManager();4. Set the spoken language.
subtitleManager.setCurrentSpeakLanguage("zh");5. Set the list of translation languages.
List<String> languageList = new ArrayList();
languageList.add("zh");
subtitleManager.setCurrentTranslateLanguages(languageList);6. Set the caption listener.
subtitleManager.setSubtitleManagerEventListener(new DingRtcEngineSubtitleManagerListener() {
@Override
public void onLanguageListsUpdated() {
// The language lists are updated.
}
@Override
public void onSubtitleServiceStatusChanged(DingRtcEngineSubtitleTypes.DingRtcSubtitleStatus status) {
// DingRtcSubtitleStatus.OPEN Caption service status: Active when enabled.
}
@Override
public void onSubtitleMessage(DingRtcEngineSubtitleTypes.DingRtcSubtitleMessage message) {
// Process the received caption message.
}
});7. Enable captions.
subtitleManager.enableSubtitle(true);Android API reference
1. Caption manager
public interface DingRtcEngineSubtitleManager {
/**
* @ingroup Android_DingRtcEngineSubtitleManager
* @since 3.8
* @brief Sets the caption manager listener.
* @param listener The listener that accepts events from the caption manager.
* @return int
* - 0: Success.
* - A non-zero value: Failure.
*/
int setSubtitleManagerEventListener(DingRtcEngineSubtitleManagerListener listener);
/**
* @ingroup Android_DingRtcEngineSubtitleManager
* @since 3.8
* @brief Enables or disables captions.
* @param enable
* - Specifies whether to enable or disable captions.
* - true: Enable captions.
* - false: Disable captions.
* @return int
* - 0: Success.
* - A non-zero value: Failure.
*/
int enableSubtitle(boolean enable);
/**
* @ingroup Android_DingRtcEngineSubtitleManager
* @since 3.8
* @brief Gets the list of supported spoken languages.
* @return The list of spoken languages.
*/
String[] getSupportedSpeakLanguages();
/**
* @ingroup Android_DingRtcEngineSubtitleManager
* @since 3.8
* @brief Sets the spoken language.
* @param language The spoken language.
* @return int
* - 0: Success.
* - A non-zero value: Failure.
*/
int setCurrentSpeakLanguage(String language);
/**
* @ingroup Android_DingRtcEngineSubtitleManager
* @since 3.8
* @brief Gets the list of supported translation languages.
* @return The list of translation languages.
*/
String[] getSupportedTranslateLanguages();
/**
* @ingroup Android_DingRtcEngineSubtitleManager
* @since 3.8
* @brief Sets the list of translation languages.
* @param languages The translation languages.
* @return int
* - 0: Success.
* - A non-zero value: Failure.
*/
int setCurrentTranslateLanguages(ArrayList<String> languages);
}
2. Caption listener
public interface DingRtcEngineSubtitleManagerListener {
/**
* @since 3.8
* @brief The callback that is invoked when the language lists are updated.
*/
void onLanguageListsUpdated();
/**
* @since 3.8
* @brief The callback that is invoked when the caption service status changes.
* @param status The caption service status.
*/
void onSubtitleServiceStatusChanged(DingRtcSubtitleStatus status);
/**
* @since 3.8
* @brief The callback that is invoked when a caption message is received.
* @param message The caption message.
*/
void onSubtitleMessage(DingRtcSubtitleMessage message);
}3. Related data classes
/**
* @brief The caption service status.
*/
public enum DingRtcSubtitleStatus {
/** The caption service is enabled. */
OPEN(0),
/** The caption service is disabled. */
CLOSE(1),
/** An error occurred in the caption service. */
ERROR(2);
}
/**
* @ingroup DingRtcDef_Android
* @since 3.8
* @brief The caption message.
*/
public static class DingRtcSubtitleMessage {
/** The user ID for the caption. */
public String userId;
/** The caption content. */
public String subtitle;
/** The serial number of the caption sentence. */
public long sentenceIndex = 0;
/** Indicates whether the sentence is complete. */
public boolean sentenceEnd = false;
/** Indicates whether the caption is a translation. */
public boolean translate = false;
/** The language of the caption. */
public String language;
/** The start time of the caption sentence. */
public long beginTime = 0;
/** The end time of the caption sentence. */
public long endTime = 0;
}