> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebellapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# my.getRecorderManager

> Get the globally unique audio recording manager.

Returns the globally unique **RecorderManager** object, which controls audio recording (start, pause, resume, stop) and its events.

```javascript theme={null}
const recorderManager = my.getRecorderManager();
```

## Return Value

| Type | Description |
| - | - |
| RecorderManager | The globally unique audio recording manager |

## RecorderManager Methods

| Method | Description |
| - | - |
| start(options) | Start recording (see options below) |
| pause() | Pause recording |
| resume() | Resume recording |
| stop() | Stop recording |

### start Options

| Property | Type | Required | Description |
| - | - | - | - |
| duration | Number | No | Recording duration in ms. Max and default: `600000` (10 minutes) |
| format | String | No | Audio format, lowercase: `aac` (default) or `pcm` |
| hideTips | Boolean | No | Hide the recording icon. Default: `false` |
| numberOfChannels | Number | No | Number of channels: `1` (default) or `2` |
| sampleRate | Number | No | Sampling rate: `8000`, `11025`, `12000`, `16000`, `22050`, `24000`, `32000`, `44100`, `48000`. Default: `8000` (Android), `44100` (iOS) |
| encodeBitRate | Number | No | Encoding bitrate; must match the sampling rate (see table below). Default: `32000` (Android), `192000` (iOS) |
| audioSource | String | No | Audio input source, from [my.getAvailableAudioSources](https://docs.rebellapp.com/jsapi/media/recorder/my.getAvailableAudioSources.md). Default: `auto` |
| frameSize | Number | No | Frame size in KB. `onFrameRecorded` fires only if `frameSize` is set and `frameFormatPcm` is `true` |
| frameFormatPcm | Boolean | No | Deliver recorded frames as PCM. Required (with `frameSize`) for `onFrameRecorded` |

### Encoding Bitrate Ranges

An invalid sampling rate / bitrate combination makes the recording fail.

| Sampling rate | Encoding bitrate range |
| - | - |
| 8000 | 16000–48000 |
| 11025 | 16000–48000 |
| 12000 | 24000–64000 |
| 16000 | 24000–96000 |
| 22050 | 32000–128000 |
| 24000 | 32000–128000 |
| 32000 | 48000–192000 |
| 44100 | 64000–320000 |
| 48000 | 64000–320000 |

## RecorderManager Events

Each `on*` method registers a listener; the matching `off*` method removes the listener passed in, or all listeners of that event if none is passed.

| Listener | Remove with | Triggered when | Listener receives |
| - | - | - | - |
| onStart(listener) | offStart | Recording starts | — |
| onPause(listener) | offPause | Recording is paused | — |
| onResume(listener) | offResume | Recording resumes | — |
| onStop(listener) | offStop | Recording stops | `tempFilePath` (String), `duration` (Number, seconds), `fileSize` (Number, bytes) |
| onError(listener) | offError | An error occurs | `error` (Number), `errorMessage` (String) |
| onFrameRecorded(listener) | offFrameRecorded | A frame of `frameSize` is captured (requires `frameSize` and `frameFormatPcm: true`) | `frameBuffer` (ArrayBuffer), `isLastFrame` (Boolean) |

## Error Codes

| Code | Message | Action |
| - | - | - |
| 2 | Invalid parameter | Check parameter values and types |
| 3 | Unknown error | Check the input parameters; the sampling rate and bitrate must match the table above |
| 4 (Android) / 8607 (iOS) | Recording is already underway | Handle this case in the interaction design |
| 7 | Recording duration is not enough | Record for more than 1 second |
| 10 | No permission to record audio | Usually the microphone permission is missing; call [my.showAuthGuide](https://docs.rebellapp.com/jsapi/device/permission-guide/my.showAuthGuide.md) |
| 2001 | User denied the authorization | Explain why the permission is needed |
| 2002 | Authorization denied | The user previously denied and chose to keep that choice; guide them to the Mini Program settings (capsule button > Settings) or call [my.openSetting](https://docs.rebellapp.com/jsapi/device/setting/my.openSetting.md) |
| 2003 | User denied the authorization and chose to keep that choice | Guide the user to the settings as for `2002` |

## Code Example

```javascript theme={null}
Page({
  onLoad() {
    this.recorderManager = my.getRecorderManager();
    this.onStop = (res) => {
      console.log('Recorded file:', res.tempFilePath, res.duration, 's');
    };
    this.onError = (err) => {
      console.error('Recording error', err.error, err.errorMessage);
    };
    this.recorderManager.onStop(this.onStop);
    this.recorderManager.onError(this.onError);
  },
  startRecording() {
    this.recorderManager.start({
      duration: 60000,
      format: 'aac',
      sampleRate: 44100,
      encodeBitRate: 128000
    });
  },
  stopRecording() {
    this.recorderManager.stop();
  },
  onUnload() {
    this.recorderManager.offStop(this.onStop);
    this.recorderManager.offError(this.onError);
  }
});
```

## Related APIs

> [card] [my.getAvailableAudioSources](https://docs.rebellapp.com/jsapi/media/recorder/my.getAvailableAudioSources.md)
>
> Get available audio sources

> [card] [my.createInnerAudioContext](https://docs.rebellapp.com/jsapi/media/audio/my.createInnerAudioContext.md)
>
> Play audio


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.