@capgo/capacitor-audio-recorder

中文文档
8.3.5发布于 2026/10/18MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 17.4万

Record audio on iOS, Android, and Web with Capacitor

原始使用文档
文档目录29 节
  1. ➡️ Get started for free
  2. Key features
  3. Why Capacitor Audio Recorder?
  4. Documentation
  5. Compatibility
  6. Install
  7. Background recording
  8. API
  9. startRecording(...)
  10. pauseRecording()
  11. resumeRecording()
  12. stopRecording()
  13. cancelRecording()
  14. resetAudioSessionForPlayback()
  15. getRecordingStatus()
  16. getCurrentAmplitude()
  17. checkPermissions()
  18. requestPermissions()
  19. addListener('recordingError', ...)
  20. addListener('recordingPaused', ...)
  21. addListener('recordingStopped', ...)
  22. addListener('recordingInterruptionBegan', ...)
  23. addListener('recordingInterruptionEnded', ...)
  24. removeAllListeners()
  25. getPluginVersion()
  26. Interfaces
  27. Type Aliases
  28. Enums
  29. Credit

@capgo/capacitor-audio-recorder

Record audio from the microphone on iOS, Android and the web with one Capacitor API. Pause, resume, read the input level and save the clip when you are done.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-audio-recorder in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-audio-recorder to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-audio-recorder for Capacitor apps

Key features

  • Record: startRecording(), stopRecording() and cancelRecording() to capture or discard a clip.
  • Pause and resume: pauseRecording() and resumeRecording() without starting a new file.
  • Input level: getCurrentAmplitude() returns the microphone level from 0 to 1 for meters and waveforms.
  • Status and events: getRecordingStatus() plus recordingPaused, recordingStopped, recordingError, and (iOS only) recordingInterruptionBegan / recordingInterruptionEnded listeners.
  • Permissions: checkPermissions() and requestPermissions() for microphone access.
  • Platforms: iOS, Android and Web. iOS uses AVFoundation, Android uses MediaRecorder, and web uses the browser recorder.

Why Capacitor Audio Recorder?

The only free and up-to-date audio recording plugin for Capacitor:

  • Same JavaScript API - Compatible interface with paid plugins
  • Full feature set - Pause/resume, configurable bitrates, sample rates
  • Cross-platform - iOS, Android, and Web support
  • Modern implementation - Uses latest platform APIs
  • Event listeners - Real-time recording status and error handling

Perfect for voice memo apps, audio messaging, podcast recording, and any app needing audio capture.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/audio-recorder/

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌
v5.*.*v5.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-audio-recorder` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-audio-recorder
npx cap sync

Background recording

The plugin does not automatically put your app into a background-safe mode, you need to configure each platform so the process is allowed to keep running while the screen is locked.

  • iOS: Enable the Background Modes → Audio capability in Xcode (or add UIBackgroundModes with an audio entry in Info.plist). With that flag enabled, startRecording will continue while the device is locked because the plugin already uses an AVAudioSession category that supports background capture.

  • Android: Recording continues as long as the app process stays alive. For hour-long sessions you should move the recording work into a foreground service with an ongoing notification to prevent the OS from stopping the process. Add the required permissions, e.g.:

    <!-- android/app/src/main/AndroidManifest.xml -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    

    Then start a foreground service before calling startRecording (or trigger the recording inside that service). The plugin itself does not create the service for you, so you can use your preferred foreground-service implementation or a background-task helper plugin to start/stop it alongside the recording UI.

API

Capacitor plugin contract for recording audio.

startRecording(...)

startRecording(options?: StartRecordingOptions | undefined) => Promise<void>

Start recording audio using the device microphone.

ParamTypeDescription
optionsStartRecordingOptionsRecording configuration options.

Since: 1.0.0


pauseRecording()

pauseRecording() => Promise<void>

Pause the ongoing recording. Only available on Android (API 24+), iOS, and Web.

Since: 1.0.0


resumeRecording()

resumeRecording() => Promise<void>

Resume a previously paused recording.

Since: 1.0.0


stopRecording()

stopRecording() => Promise<StopRecordingResult>

Stop the current recording and persist the recorded audio.

Returns: Promise<StopRecordingResult>

Since: 1.0.0


cancelRecording()

cancelRecording() => Promise<void>

Cancel the current recording and discard any captured audio.

Since: 1.0.0


resetAudioSessionForPlayback()

resetAudioSessionForPlayback() => Promise<void>

Reset the iOS audio session to .playback for normal-volume playback of recorded audio in the same app process (for example via an HTML audio element). No-op on Android and Web.

Since: 8.2.10


getRecordingStatus()

getRecordingStatus() => Promise<GetRecordingStatusResult>

Retrieve the current recording status.

Returns: Promise<GetRecordingStatusResult>

Since: 1.0.0


getCurrentAmplitude()

getCurrentAmplitude() => Promise<GetCurrentAmplitudeResult>

Retrieve the current input amplitude (microphone level) as a normalized number in the [0, 1] range.

Intended for driving live visualizations such as VU meters or waveforms while recording. Returns 0 when no recording is active. Designed for UI-rate polling — a 60–100 ms interval is a good starting point for a waveform. Avoid calling it in a tight loop; each call crosses the JS/native bridge.

Returns: Promise<GetCurrentAmplitudeResult>

Since: 8.1.0


checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Return the current permission state for accessing the microphone.

Returns: Promise<PermissionStatus>

Since: 1.0.0


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Request permission to access the microphone.

Returns: Promise<PermissionStatus>

Since: 1.0.0


addListener('recordingError', ...)

addListener(eventName: 'recordingError', listenerFunc: (event: RecordingErrorEvent) => void) => Promise<PluginListenerHandle>

Listen for recording errors.

ParamType
eventName'recordingError'
listenerFunc(event: RecordingErrorEvent) => void

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('recordingPaused', ...)

addListener(eventName: 'recordingPaused', listenerFunc: () => void) => Promise<PluginListenerHandle>

Listen for pause events emitted when a recording is paused.

ParamType
eventName'recordingPaused'
listenerFunc() => void

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('recordingStopped', ...)

addListener(eventName: 'recordingStopped', listenerFunc: (event: RecordingStoppedEvent) => void) => Promise<PluginListenerHandle>

Listen for recording completion events.

ParamType
eventName'recordingStopped'
listenerFunc(event: StopRecordingResult) => void

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('recordingInterruptionBegan', ...)

addListener(eventName: 'recordingInterruptionBegan', listenerFunc: () => void) => Promise<PluginListenerHandle>

Listen for the start of an audio session interruption while recording.

Only emitted on iOS when the system pauses or archives the active recording (for example when a phone call begins).

ParamType
eventName'recordingInterruptionBegan'
listenerFunc() => void

Returns: Promise<PluginListenerHandle>

Since: 8.2.0


addListener('recordingInterruptionEnded', ...)

addListener(eventName: 'recordingInterruptionEnded', listenerFunc: (event: RecordingInterruptionEndedEvent) => void) => Promise<PluginListenerHandle>

Listen for the end of an audio session interruption while recording.

Only emitted on iOS. Usually follows recordingInterruptionBegan, but may also fire after a recorder failure without a prior began event, with shouldResume set to false.

ParamType
eventName'recordingInterruptionEnded'
listenerFunc(event: RecordingInterruptionEndedEvent) => void

Returns: Promise<PluginListenerHandle>

Since: 8.2.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all registered listeners.

Since: 1.0.0


getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Get the native Capacitor plugin version.

Returns: Promise<{ version: string; }>

Since: 1.0.0


Interfaces

StartRecordingOptions

Options accepted by {@link CapacitorAudioRecorderPlugin.startRecording}.

PropTypeDescriptionSince
audioSessionCategoryOptionsAudioSessionCategoryOption[]The audio session category options for recording. Only available on iOS.1.0.0
audioSessionModeAudioSessionModeThe audio session mode for recording. Only available on iOS.1.0.0
bitRatenumberThe audio bit rate in bytes per second. Only available on Android and iOS.1.0.0
sampleRatenumberThe audio sample rate in Hz. Only available on Android and iOS.1.0.0
resetToPlaybackOnStopbooleanWhen true, reset the iOS AVAudioSession category to .playback when recording stops or is canceled. This avoids quiet in-app playback of the just-recorded file while the session is still configured for .playAndRecord. Only available on iOS.8.2.10

StopRecordingResult

Result returned by {@link CapacitorAudioRecorderPlugin.stopRecording}.

PropTypeDescriptionSince
blobBlobThe recorded audio as a Blob. Only available on Web.1.0.0
durationnumberThe duration of the recording in milliseconds.1.0.0
uristringThe URI pointing to the recorded file. Only available on Android and iOS.1.0.0

GetRecordingStatusResult

Result returned by {@link CapacitorAudioRecorderPlugin.getRecordingStatus}.

PropTypeDescriptionSince
statusRecordingStatusThe current recording status.1.0.0

GetCurrentAmplitudeResult

Result returned by {@link CapacitorAudioRecorderPlugin.getCurrentAmplitude}.

PropTypeDescriptionSince
valuenumberThe current input amplitude normalized to the [0, 1] range, where 0 represents silence and 1 represents the maximum level the platform can report. The value is 0 when no recording is active. Note: the source signal differs between platforms — Android reports the peak sample amplitude since the last call, iOS reports the average power in dB converted to linear, and Web reports the RMS of the latest frame. Consumers that need cross-platform parity may want to apply a per-platform scaling curve.8.1.0

PermissionStatus

Permission information returned by {@link CapacitorAudioRecorderPlugin.checkPermissions} and {@link CapacitorAudioRecorderPlugin.requestPermissions}.

PropTypeDescriptionSince
recordAudioPermissionStateThe permission state for audio recording.1.0.0

PluginListenerHandle

PropType
remove() => Promise<void>

RecordingErrorEvent

Event emitted when an error occurs during recording.

PropTypeDescriptionSince
messagestringThe error message.1.0.0
uristringURI of the most recently preserved segment when the error occurred. Emitted on iOS. The segment may be partial. May be an empty string when no segment was preserved yet.8.2.0

RecordingInterruptionEndedEvent

Event emitted when an audio session interruption ends on iOS (for example after a phone call).

PropTypeDescriptionSince
shouldResumebooleanWhether the plugin resumed recording after the interruption.8.2.0

Type Aliases

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

RecordingStoppedEvent

Event emitted when a recording completes.

StopRecordingResult

Enums

AudioSessionCategoryOption

MembersValue
AllowAirPlay'ALLOW_AIR_PLAY'
AllowBluetooth'ALLOW_BLUETOOTH'
AllowBluetoothA2DP'ALLOW_BLUETOOTH_A2DP'
DefaultToSpeaker'DEFAULT_TO_SPEAKER'
DuckOthers'DUCK_OTHERS'
InterruptSpokenAudioAndMixWithOthers'INTERRUPT_SPOKEN_AUDIO_AND_MIX_WITH_OTHERS'
MixWithOthers'MIX_WITH_OTHERS'
OverrideMutedMicrophoneInterruption'OVERRIDE_MUTED_MICROPHONE_INTERRUPTION'

AudioSessionMode

MembersValue
Default'DEFAULT'
GameChat'GAME_CHAT'
Measurement'MEASUREMENT'
SpokenAudio'SPOKEN_AUDIO'
VideoChat'VIDEO_CHAT'
VideoRecording'VIDEO_RECORDING'
VoiceChat'VOICE_CHAT'

RecordingStatus

MembersValue
Inactive'INACTIVE'
Recording'RECORDING'
Paused'PAUSED'

Credit

This plugin was inspired from: https://github.com/kesha-antonov/react-native-background-downloader

版本与发布记录

@capgo/capacitor-audio-recorder 共发布 42 个版本,首次发布于 2025/10/27;过去 12 个月发布了 35 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.3.5latest2026/10/1821 天前
8.3.42026/10/1525 天前
8.3.32026/10/1327 天前
8.3.22026/10/091 个月前
8.3.12026/10/091 个月前
8.3.02026/10/091 个月前

关于 @capgo/capacitor-audio-recorder 的常见问题

@capgo/capacitor-audio-recorder 是什么?

Record audio on iOS, Android, and Web with Capacitor

如何安装 @capgo/capacitor-audio-recorder?

在项目目录运行 npm install @capgo/capacitor-audio-recorder,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-audio-recorder 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-audio-recorder 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-audio-recorder 可以商用吗?

@capgo/capacitor-audio-recorder 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-audio-recorder 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-audio-recorder 在 2026/10/09 – 2026/11/07 这 30 天内被下载 173,912 次,日均约 5,797 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-audio-recorder 还在维护吗?

最新版本 8.3.5 发布于 2026/10/18(21 天前);至今共发布 42 个版本,其中过去 12 个月发布了 35 个;首次发布于 2025/10/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。