Skip to main content

Voice Message

Users can record and send voice messages through the built-in input component of Global IM UIKit. The message will appear in the message list component of the conversation page. The SDK generates and sends a high-definition voice message content object RCHQVoiceMessage (type identifier: RC:HQVcMsg) by default.

hqvoice-message(width=250)

Limitations

The voice input feature currently has the following limitations:

  • Global IM UIKit only supports sending voice messages in one-to-one chat and group chat sessions.
  • Users must record audio content that is at least 1 second long and no longer than 60 seconds.
  • Users cannot pause while recording a voice message.

Usage

The voice message input feature is enabled by default in the input bar component. Long press the voice button to record and release to send.

When entering text, the recording button will switch to a send button. When the text input is empty, it will switch back to the recording button.

Voice Message Display

In the message list, voice messages will display decibel levels, duration, and other information. Users can click the play button to view and play the voice message, which can be played multiple times. When the voice message is displayed for the first time, the voice file will be automatically downloaded and cached locally.

Voice Decibel

During recording, the decibel information of the sound is recorded and sent along with the high-definition voice message. The decibel information is converted into a JSON format string and placed in the extra of RCHQVoiceMessage, as shown below:

{
"HQVoicePowers": "level,level,level,level,..."
}

Customization

Customization of voice messages involves the recording button icon, recording events, and the display UI of the voice message.

Custom Voice Message UI

The SDK generates and sends a high-definition voice message (RC:HQVoiceMsg) by default, which is displayed in the message list using the RCVoiceMessageCell template. Developers can create a Cell that inherits from RCVoiceMessageCell to customize the display of voice messages. For details, see Modify Message Display Style.

Handling Recording Events

Global IM UIKit implements recording-related events in RCChatViewController:

@protocol RCVoiceRecordDelegate <NSObject>

@optional

/// Will start voice recording
- (BOOL)voiceRecordWillBegan;

/// Has started voice recording
- (void)voiceRecordDidBegan;

/// Cancel voice recording
- (void)voiceRecordDidCancel;

/// Voice recording ended
- (void)voiceRecordDidEnd:(RCAudioModel *)audioModel;

/// Voice recording interrupted
- (void)voiceRecordDidInterrupt:(RCAudioModel *)audioModel;

/// Voice recording failed
- (void)voiceRecordDidFailed:(NSError *)error;

@end

Custom Recording Button UI

In the input component, the recording button is displayed by default, controlled by recordItem. Developers can set the image and event:


- (void)viewDidLoad {
[super viewDidLoad];
self.inputBar.recordItem.image = CustomImage;
self.inputBar.recordItem.action = ^(RCBarItem *item) {
// custom action
};
self.inputBar.rightItems = @[self.inputBar.rightItems];
}