スタートガイド
インストール手順と、このプラグインの完全な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アシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いのAIツールに Capgo のスキルを追加してください:
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';クイックスタート
「クイックスタート」セクションマイク権限をリクエストして録音し、停止後にネイティブファイルURI(またはWeb URI)を読み取ります Blob).
import { Capacitor } from '@capacitor/core';import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
const mic = await CapacitorAudioRecorder.requestPermissions();if (mic.recordAudio !== 'granted') { throw new Error('Microphone permission required');}
await CapacitorAudioRecorder.startRecording({ sampleRate: 44100, bitRate: 128000, resetToPlaybackOnStop: true, // iOS only: restore playback-friendly audio session after stop});
const { uri, blob, duration } = await CapacitorAudioRecorder.stopRecording();const clipRef = Capacitor.getPlatform() === 'web' ? blob : uri;console.log('Saved clip', clipRef, duration);例:一時停止付きボイスメモ
セクション「例: 一時停止付きボイスメモ」await CapacitorAudioRecorder.startRecording();// user taps pause during a long noteawait CapacitorAudioRecorder.pauseRecording();await CapacitorAudioRecorder.resumeRecording();const clip = await CapacitorAudioRecorder.stopRecording();pauseRecording は Android (API 24+)、iOS、Web で利用可能です。
例:ライブレベルメーター
セクション「例: ライブレベルメーター」ポーリング getCurrentAmplitude() ステータスが RECORDINGの間、タイマー(約 60〜100 ms)で。値は正規化されます 0 まで 1、ただし基になるシグナルはプラットフォームごとに異なります(Android はピーク、iOS は平均パワー、Web は RMS)。見た目を揃えたい場合は、プラットフォームごとに小さなスケール係数を適用してください。
const tick = async () => { const { status } = await CapacitorAudioRecorder.getRecordingStatus(); if (status !== 'RECORDING') return; const { value } = await CapacitorAudioRecorder.getCurrentAmplitude(); updateMeterUi(value);};例:テイクを破棄する
「例:テイクを破棄する」というセクションawait CapacitorAudioRecorder.startRecording();await CapacitorAudioRecorder.cancelRecording(); // no file persistedよくある落とし穴
「よくある落とし穴」セクション- Webとネイティブの戻り値の形式: AndroidとiOSの戻り値は
uriとstopRecording。Webの戻り値はblob(また省略される場合がありますuri). - iOSで録音後に再生音量が小さい:設定
resetToPlaybackOnStop: trueにおけるstartRecordingユーザーが同じセッション内でクリップを再生する場合。 - バックグラウンド録音: プラグイン自体はバックグラウンドオーディオを有効にしません。iOSでロック中に録音する必要がある場合は、Audio background modeを追加してください。
- amplitudeを呼びすぎない: 各
getCurrentAmplitude呼び出しはブリッジを経由します。タイトループではなく、UIのintervalを使ってください。
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
「stopRecording」セクション現在の録音を停止し、録音したオーディオを保存します。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
const result = await CapacitorAudioRecorder.stopRecording();console.log(result);cancelRecording
「cancelRecording」セクション現在の録音をキャンセルし、キャプチャしたオーディオを破棄します。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
await CapacitorAudioRecorder.cancelRecording();getRecordingStatus
「getRecordingStatus」セクション現在の録音ステータスを取得します。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
const result = await CapacitorAudioRecorder.getRecordingStatus();console.log(result);getCurrentAmplitude
「getCurrentAmplitude」セクション現在の入力振幅(マイクレベル)を、正規化された数値として取得します。 [0, 1] 範囲。
録音中のVUメーターや波形などのライブビジュアライゼーションに使用することを想定しています。戻り値は 0 録音がアクティブでない場合に返されます。UI更新レートでのポーリング向けに設計されており、波形表示なら60〜100ms間隔から始めるのがおすすめです。タイトなループ内で呼び出さないでください。呼び出しのたびにJS/native bridgeを介して通信が発生します。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
const result = await CapacitorAudioRecorder.getCurrentAmplitude();console.log(result);checkPermissions
「checkPermissions」セクションマイクへのアクセス権限の現在の状態を返します。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
const result = await CapacitorAudioRecorder.checkPermissions();console.log(result);requestPermissions
「requestPermissions」セクションマイクへのアクセス権限をリクエストします。
import { CapacitorAudioRecorder } from '@capgo/capacitor-audio-recorder';
const result = await CapacitorAudioRecorder.requestPermissions();console.log(result);型リファレンス
「型リファレンス」セクションStartRecordingOptions
セクション「StartRecordingOptions」受け付けるオプション。
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」返される結果。
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」返される結果。
export interface GetRecordingStatusResult { /** * The current recording status. * * @since 1.0.0 */ status: RecordingStatus;}GetCurrentAmplitudeResult
「GetCurrentAmplitudeResult」セクション返される結果。
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」セクションと によって返される権限情報。
export interface PermissionStatus { /** * The permission state for audio recording. * * @since 1.0.0 */ recordAudio: PermissionState;}RecordingErrorEvent
「RecordingErrorEvent」セクション録音中にエラーが発生した際に発行されるイベント。
export interface RecordingErrorEvent { /** * The error message. * * @since 1.0.0 */ message: string;}RecordingStoppedEvent
「RecordingStoppedEvent」セクション録音が完了したときに発行されるイベント。
export type RecordingStoppedEvent = StopRecordingResult;AudioSessionCategoryOption
「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
「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';Source of Truth
「Source Of Truth」セクションこのページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。
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-video-player を使用する際のネイティブ機能については、 @capgo/capacitor-video-player @capgo/capacitor-video-player. の実装の詳細については