Audio messages

Update time: 2024/03/07 11:13:59

NIM SDK allows users to make high-definition voice recordings and playbacks for processing audio messages.

The Flutter SDK does not support speech processing on macOS and Web.

Audio recording

NIM SDK provides the AudioService class for audio recording.


The microphone permission has been granted.


  1. Register the onAudioRecordStatus event stream to track changes of the audio recording status. The recordState enumeration in the RecordInfo of the callback defines the recording states.

    type Description
    READY Enum type The recorder is ready. The interface is used to close local audio and video playback before recording. The state is optional (not supported on Windows).
    START Enum type Start recording
    REACHED_MAX Enum type The audio duration reached the specified maximum recording time (not supported on Windows)
    SUCCESS Enum type Recording is completed successfully
    FAIL Enum type An error occurs while recording (the parameter is not supported on Windows)
    CANCEL Enum type The recording is canceled.
    dart/// Listen to the recording event
    NimCore.instance.audioService.onAudioRecordStatus.listen((RecordInfo recordInfo) {
  2. Start recording by calling the startRecord method.

    Parameter Type Description
    recordType AudioOutputFormat The type of a recording file. AAC or AMR
    maxDuration int The maximum duration for one recording. If the maximum duration is reached, recording will stop automatically, 120 seconds by default.
dart/// Start recording. If the callsucceeds, the `READY` and `START`callback will be triggered.
/// The maximum duration for onerecording. If the maximum duration isreached, recording will stopautomatically. 120 seconds by default.
  1. (Optional) Call the following methods as needed.

    Method Return value type Description
    getAmplitude int Get the maximum amplitude of the current recording, and update the data every 40ms. The method is not supported on Windows
    isAudioRecording bool Whether recording is in progress. The method is not supported on Windows.
    cancelRecord bool Cancel recording
    dart/// Get the maximum amplitude of the current recording, and update the data every 40ms.
    dart/// Whether recording is in progress. 
  2. Stop recording by calling the stopRecord method.

    dart// Stop recording


NIM SDK allows you to convert audio files into text.

How it works:

  • Record an audio file (up to 60 seconds).
  • Upload the audio file to the cloud storage server and return a URL.
  • Pass the URL and related parameters in the speech-to-text interface, and return the converted text.


To activate the speech-to-text feature, contact the sales manager using the WhatsApp provided on the homepage of CommsEase website


Convert speech to text by calling the voiceToText method in the messageService class.

If you have not activate the speech-to-text service, the 403 error will be returned.

dartvar result = await NimCore.instance.messageService
Was this page helpful?
  • Audio recording
  • Prerequisites
  • Implementation
  • Speech-to-text
  • Prerequisites
  • Implementation