Skip to main content

Voice Messages

Users can record and send voice messages through the built-in input component in IMKit. The messages will appear in the message list component of the chat UI. By default, the SDK generates and sends messages containing the high-quality voice message content object RCHQVoiceMessage (type identifier: RC:HQVcMsg).

hqvoice-message(width=250) hqvoice-message-read(width=250)

Limitations

The voice input feature currently has the following restrictions:

  • IMKit only supports sending voice messages in one-to-one chat and group chat conversations.
  • Users must record audio content lasting at least 1 second and no longer than 60 seconds.
  • Users cannot pause while recording a voice message.
  • Voice messages cannot be sent during ongoing video or voice calls.

Usage

IMKit enables the voice message input feature by default in the input bar component. The input bar includes a toggle button for voice input by default.

Sending Voice Messages

To send a voice message, users must first record the message using RCVoiceRecorder in the input bar. By default, the voice message icon appears on the left side of the input field. Clicking this icon reveals the recording button ("Hold to Talk"). Users can record a voice message by pressing and holding the recording button.

The recorded voice must be at least 1 second long and no longer than 60 seconds. If the message is shorter than 1 second when the stop button is clicked, the message will not be saved. During recording, users can swipe up to cancel or abandon the cancellation. Once the button is released, the SDK sends the recorded content by default. Previewing voice messages before sending is not supported, and audio files in voice messages cannot be paused during playback.

hqvoice-message(width=250)

Voice Message Types

Voice Messages in the Message List

You can receive voice messages in one-to-one chat, group chat, and system conversations. Voice messages are displayed in the message list.

Users can view and play voice messages by clicking the play button. Unplayed voice messages are marked with a red dot and can be played multiple times. However, users can only listen to voice messages within the client application and cannot save them to their devices.

Only one audio file can be played at a time in the chat UI. If you attempt to play another message while one is playing, the currently playing message will pause.

hqvoice-message(width=250) hqvoice-message(width=250)

IMKit downloads high-quality voice messages by default and continuously plays unplayed voice messages below the current one after playback starts. You can disable this behavior before displaying the chat UI by setting the enableContinuousReadUnreadVoice property of RCConversationViewController.

// `NO` disables continuous playback.
chatVC.enableContinuousReadUnreadVoice = NO;
[self.navigationController pushViewController:chatVC animated:YES];

Customization

Customizing voice messages involves the voice input toggle icon in the input bar, the audio recording interface, and the high-quality voice message display UI.

Customizing the Voice Message UI

IMKit generates and sends high-quality voice messages (RC:HQVoiceMsg) by default, displayed in the message list using the RCHQVoiceMessageCell template.

All message templates in IMKit inherit from RCMessageCell. Custom message cells must also inherit from RCMessageCell. For details, see Modifying Message Display Styles.

You can also directly replace the style resources, string resources, and icon resources referenced in the short video message display template in RongCloud.bundle. Refer to the resources used in the IMKit source code RCHQVoiceMessageCell.m.

Input Bar and Recording Popup Style Resources

You can also directly replace the style resources related to the input bar and recording popup in RongCloud.bundle. Below is a partial list of icons.

IconImageDescription
inputbar_voice(width=14)The icon used for the voice input button, toggling to the voice message recording view during message input. inputbar_voice_dark corresponds to the icon in dark mode.
voice_unread(width=14)Unread status of high-quality voice messages sent by the local user.

For more icon resources, refer to the IMKit source code RCHQVoiceMessageCell.m, RCVoiceCaptureControl.m, etc.

IMKit provides recording-related events in RCConversationViewController. You can override these methods for custom operations:

  • (void)onBeginRecordEvent;: Triggered when voice message recording starts.
  • (void)onEndRecordEvent;: Triggered when voice message recording ends.
  • (void)onCancelRecordEvent;: Triggered when voice message recording is canceled. This callback does not trigger onEndRecordEvent.

For details, see Page Event Listeners.

Hiding the Voice Input Toggle Button

You can modify the input toolbar style RCChatSessionInputBarControlStyle by setting the chatSessionInputBarControl property of RCConversationViewController after viewDidLoad to remove the voice/text toggle button.

RCChatSessionInputBarControlStyle style = RC_CHAT_INPUT_BAR_STYLE_CONTAINER_EXTENTION;
[self.yourChatVC.chatSessionInputBarControl setInputBarType:RCChatSessionInputBarControlDefaultType style:style];