开始使用
复制一个包含安装步骤和本插件完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-audio-recorder`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/audio-recorder/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
安装您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-audio-recorder` plugin in my project.如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:
bun add @capgo/capacitor-audio-recorderbunx cap sync导入
导入import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';API 简介
标题为“API 简介”的部分startRecording
标题为“startRecording”使用设备麦克风开始录音。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.startRecording();pauseRecording
标题为“pauseRecording”暂停正在进行的录音。仅在 Android (API 24+)、iOS 和 Web 上可用。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.pauseRecording();resumeRecording
标题为“resumeRecording”恢复之前暂停的录音。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.resumeRecording();stopRecording
Section titled “stopRecording”停止当前录音并保存录音音频。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.stopRecording();cancelRecording
Section titled “cancelRecording”取消当前录音并丢弃捕获的音频。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.cancelRecording();getRecordingStatus
Section titled “getRecordingStatus”获取当前录音状态。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.getRecordingStatus();getCurrentAmplitude
Section titled “getCurrentAmplitude”获取当前输入振幅(麦克风音量)作为归一化的数字值,范围在 [0, 1] 复制到剪贴板
适用于在录制时驱动实时视觉化,如VU计数器或波形图。 0 当没有正在录制的时。适用于UI率轮询 —— 60–100 ms的间隔是一个很好的起始点。避免在紧密循环中调用它;每次调用都会跨越JS/native桥梁。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.getCurrentAmplitude();checkPermissions
检查权限获取当前访问麦克风的权限状态。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.checkPermissions();requestPermissions
请求权限请求访问麦克风。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.requestPermissions();类型参考
类型参考StartRecordingOptions
开始录制选项Options accepted by Capgo
export interface StartRecordingOptions { /** * The audio session category options for recording. Only available on iOS. * * @since 1.0.0 */ audioSessionCategoryOptions?: AudioSessionCategoryOption[];
/** * The audio session mode for recording. Only available on iOS. * * @since 1.0.0 */ audioSessionMode?: AudioSessionMode;
/** * The audio bit rate in bytes per second. * Only available on Android and iOS. * * @since 1.0.0 */ bitRate?: number;
/** * The audio sample rate in Hz. * Only available on Android and iOS. * * @since 1.0.0 */ sampleRate?: number;}StopRecordingResult
标题:StopRecordingResult返回的结果由 Capgo
export interface StopRecordingResult { /** * The recorded audio as a Blob. Only available on Web. * * @since 1.0.0 */ blob?: Blob;
/** * The duration of the recording in milliseconds. * * @since 1.0.0 */ duration?: number;
/** * The URI pointing to the recorded file. Only available on Android and iOS. * * @since 1.0.0 */ uri?: string;}GetRecordingStatusResult
标题:GetRecordingStatusResult返回的结果由 Capgo
export interface GetRecordingStatusResult { /** * The current recording status. * * @since 1.0.0 */ status: RecordingStatus;}GetCurrentAmplitudeResult
标题:GetCurrentAmplitudeResult返回的结果由 Capgo
export interface GetCurrentAmplitudeResult { /** * The 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. * * @since 8.1.0 */ value: number;}PermissionStatus
标题:PermissionStatus__CAPGO_KEEP_0__返回的权限信息和__CAPGO_KEEP_1__返回的权限信息.
export interface PermissionStatus { /** * The permission state for audio recording. * * @since 1.0.0 */ recordAudio: PermissionState;}RecordingErrorEvent
标题:记录错误事件当记录过程中发生错误时发出的事件。
export interface RecordingErrorEvent { /** * The error message. * * @since 1.0.0 */ message: string;}RecordingStoppedEvent
标题:记录完成事件当记录完成时发出的事件。
export type RecordingStoppedEvent = StopRecordingResult;AudioSessionCategoryOption
标题:音频会话类别选项iOS上可用的音频会话类别选项。
export enum AudioSessionCategoryOption { 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
标题:音频会话模式iOS 上可用的音频会话模式。
export enum AudioSessionMode { Default = 'DEFAULT', GameChat = 'GAME_CHAT', Measurement = 'MEASUREMENT', SpokenAudio = 'SPOKEN_AUDIO', VideoChat = 'VIDEO_CHAT', VideoRecording = 'VIDEO_RECORDING', VoiceChat = 'VOICE_CHAT',}RecordingStatus
名为“RecordingStatus”的部分录音状态
export enum RecordingStatus { Inactive = 'INACTIVE', Recording = 'RECORDING', Paused = 'PAUSED',}PermissionState
名为“PermissionState”的部分Capacitor 支持的平台权限状态。
export type PermissionState = 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';本页面是根据插件的 src/definitions.ts重新同步公共 API 时,重新运行上游的同步。
继续从 Getting Started
标题:继续从 Getting Started如果您正在使用 Getting Started 来规划原生媒体和界面行为,连接它与 使用 @capgo/capacitor-audio-recorder 原生能力在使用 @capgo/capacitor-audio-recorder 中 使用 @capgo/capacitor-live-activities 原生能力在使用 @capgo/capacitor-live-activities 中 @capgo/capacitor-live-activities @capgo/capacitor-live-activities 的实现细节 使用 @capgo/capacitor-video-player 为使用@capgo/capacitor-视频播放器的原生能力, @capgo/capacitor-视频播放器 为@capgo/capacitor-视频播放器的实现细节。