スタートガイド
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-speech-recognition`
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/speech-recognition/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-speech-recognition` plugin in my project.手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
npm install @capgo/capacitor-speech-recognitionnpx cap syncインポート
「インポート」セクションimport { SpeechRecognition } from '@capgo/capacitor-speech-recognition';クイックスタート
「クイックスタート」セクションマイクの使用許可をリクエストし、 partialResults リスナーをアタッチして、ストリーミング更新付きのセッションを開始します。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.requestPermissions();
const partialListener = await SpeechRecognition.addListener('partialResults', ({ matches }) => { setTranscript(matches?.[0] ?? '');});
await SpeechRecognition.start({ language: 'en-US', partialResults: true });
// When leaving the screen:await SpeechRecognition.stop();await partialListener.remove();よくある落とし穴
「よくある落とし穴」セクション- クリーンアップ: 画面を離れる際にリスナーを解除してください。
- ロケール: UIと一致するBCP 47タグを使用してください。
- Web: 非対応です。Webのみの音声入力が必要な場合は、別途ブラウザの音声 API を使用してください。
API の概要
「API 概要」セクションavailable
「利用可能」セクション現在のデバイスでネイティブの音声認識サービスが利用可能か確認します。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.available();console.log(result);isOnDeviceRecognitionAvailable
「isOnDeviceRecognitionAvailable」セクション選択したロケールで、プラットフォームのより新しいオンデバイス認識パスが利用可能か確認します。
機能を有効にする前に、この機能チェックを使用してください。 useOnDeviceRecognition.
A true 結果が true の場合、現在のデバイス、OSバージョン、およびロケールで、そのプラットフォームの新しいオンデバイスパスが利用可能です。
戻り値 false デバイスがレガシーな認識パスのみをサポートしている場合です。
プラットフォーム SDK ドキュメント: iOS: Speech Android: SpeechRecognizer
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.isOnDeviceRecognitionAvailable();console.log(result);start
「start」セクション音声のキャプチャと文字起こしを開始します。
次の場合: partialResults が true、返されるPromiseは即座に解決され、更新は partialResults セッションが終了するまでリスナーを通じてストリーミングされます。
デフォルトのパスは、後方互換性のためにレガシーな認識動作を維持します。
渡すのは useOnDeviceRecognition: true 確認した後にのみです。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.start();console.log(result);リスニングを停止し、ネイティブリソースを解放します。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.stop();forceStop
「forceStop」セクション現在のセッションを強制終了します。
Androidでは、まず通常の停止を試行し、失敗した場合はdestroy/recreateを実行します。 timeout.
iOSでは、現在のセッションが即座に停止されます。
部分的な文字起こしデータがキャッシュされている場合、それは partialResults リスナーを通じて forced: true.
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.forceStop();getLastPartialResult
「getLastPartialResult」セクション最後にキャッシュされた部分的な文字起こし結果を取得します。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.getLastPartialResult();console.log(result);setPTTState
「setPTTState」セクション現在のpush-to-talkボタンの状態を更新します。
これと併せて使用するか、 continuousPTT またはカスタムのhold-to-talkフローで使用します。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.setPTTState({ held: true });getSupportedLanguages
「getSupportedLanguages」セクション基盤となる認識エンジンがサポートしているロケールを取得します。
Android 13以降のデバイスではこのリストが公開されなくなりました。その場合は languages 空になります。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.getSupportedLanguages();console.log(result);isListening
「isListening」セクションプラグインが現在、音声をアクティブにリッスンしているかどうかを返します。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.isListening();console.log(result);checkPermissions
「checkPermissions」セクション現在の権限状態を取得します。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.checkPermissions();console.log(result);requestPermissions
「requestPermissions」セクションマイクと音声認識の権限をリクエストします。
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.requestPermissions();console.log(result);型リファレンス
「型リファレンス」セクションSpeechRecognitionAvailability
「SpeechRecognitionAvailability」セクションexport interface SpeechRecognitionAvailability { available: boolean;}SpeechRecognitionStartOptions
「SpeechRecognitionStartOptions」セクション呼び出し時の認識動作を設定します。
export interface SpeechRecognitionStartOptions { /** * Locale identifier such as `en-US`. When omitted the device language is used. */ language?: string; /** * Maximum number of final matches returned by native APIs. Defaults to `5`. */ maxResults?: number; /** * Prompt message shown inside the Android system dialog (ignored on iOS). */ prompt?: string; /** * When `true`, Android shows the OS speech dialog instead of running inline recognition. * Defaults to `false`. */ popup?: boolean; /** * Emits partial transcription updates through the `partialResults` listener while audio is captured. */ partialResults?: boolean; /** * Enables native punctuation handling where supported (iOS 16+). */ addPunctuation?: boolean; /** * Opt in to the platform's newer on-device recognition path when available. * * On iOS 26+, this uses Apple's `SpeechAnalyzer` / `SpeechTranscriber` pipeline. * On recent Android versions, this uses the on-device `SpeechRecognizer` path. * * It is intentionally opt-in so existing apps keep the legacy flow unless they choose * to roll out the new behavior. * * Use {@link SpeechRecognitionPlugin.isOnDeviceRecognitionAvailable} before enabling it in production. * * Platform SDK docs: * iOS: [Speech](https://developer.apple.com/documentation/speech), * [SpeechAnalyzer](https://developer.apple.com/documentation/speech/speechanalyzer), * [SpeechTranscriber](https://developer.apple.com/documentation/speech/speechtranscriber) * Android: [SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer) * * Defaults to `false`. */ useOnDeviceRecognition?: boolean; /** * Allow a number of milliseconds of silence before splitting the recognition session into segments. * Required to be greater than zero and currently supported on Android only. */ allowForSilence?: number; /** * EXPERIMENTAL: Keep a PTT session alive across silence by restarting recognition while the button stays held. * * This restart behavior is implemented for Android inline recognition and iOS native recognition. */ continuousPTT?: boolean;}SpeechRecognitionMatches
「SpeechRecognitionMatches」セクションexport interface SpeechRecognitionMatches { matches?: string[];}ForceStopOptions
「ForceStopOptions」セクションオプション
export interface ForceStopOptions { /** * Android only: timeout in milliseconds before forcing stop via destroy/recreate. * * On iOS, the current session is stopped immediately and this value is ignored. * * Defaults to `1500`. */ timeout?: number;}LastPartialResult
「LastPartialResult」セクション結果
export interface LastPartialResult { /** * Whether a partial result is currently cached. */ available: boolean; /** * The most recent transcript text known to the native recognizer. */ text: string; /** * All current match alternatives when available. */ matches?: string[];}PTTStateOptions
「PTTStateOptions」セクションオプション
export interface PTTStateOptions { /** * Whether the PTT button is currently held. */ held: boolean;}SpeechRecognitionLanguages
「SpeechRecognitionLanguages」セクションexport interface SpeechRecognitionLanguages { languages: string[];}SpeechRecognitionListening
「SpeechRecognitionListening」セクションexport interface SpeechRecognitionListening { listening: boolean;}SpeechRecognitionPermissionStatus
「SpeechRecognitionPermissionStatus」セクション返される権限マップ checkPermissions と requestPermissions.
export interface SpeechRecognitionPermissionStatus { speechRecognition: PermissionState;}SpeechRecognitionSegmentResultEvent
「SpeechRecognitionSegmentResultEvent」セクションセグメント化された結果が生成されるたびに発生します (Androidのみ)。
export interface SpeechRecognitionSegmentResultEvent { matches: string[];}SpeechRecognitionPartialResultEvent
「SpeechRecognitionPartialResultEvent」セクション部分的な文字起こしが生成されるたびに発生します。
export interface SpeechRecognitionPartialResultEvent { /** * Current recognition matches when the native recognizer reports them. * * This can be omitted for forced or accumulated-only payloads. */ matches?: string[]; /** * Accumulated transcription from earlier continuous PTT cycles. */ accumulated?: string; /** * Final accumulated text including the current result. */ accumulatedText?: string; /** * `true` when the plugin is restarting recognition inside a continuous PTT session. */ isRestarting?: boolean; /** * `true` when the payload was emitted by `forceStop()`. */ forced?: boolean;}SpeechRecognitionListeningEvent
「SpeechRecognitionListeningEvent」セクションリスニング状態が変化したときに発生します。
export interface SpeechRecognitionListeningEvent { /** * Finite state of the recognition session. */ state?: ListeningFiniteState; /** * Unique identifier for the current listening session. */ sessionId?: number; /** * Why this state transition occurred. */ reason?: ListeningReason; /** * Error code when the transition is caused by an error. */ errorCode?: string; /** * Backward-compatible binary state used by earlier releases. */ status?: 'started' | 'stopped';}Source of Truth
「Source Of Truth」セクションこのページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。
Getting Startedの続きを進める
「Getting Started からの続き」セクション使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます @capgo/capacitor-speech-recognition の使用方法 @capgo/capacitor-speech-recognition を使用して Native Build の機能を利用する場合: API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。