コンテンツにスキップ

はじめに

ターミナル画面
bun add @capgo/capacitor-speech-recognition
bunx cap sync
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';

現在のデバイスで使用可能なネイティブの音声認識サービスが利用できるかどうかを確認します。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.available();

isOnDeviceRecognitionAvailable

「isOnDeviceRecognitionAvailable」を選択

選択した言語で利用可能なデバイス上の認識パスが新しいかどうかを確認します。

この機能を有効にする前に使用する機能チェックです。 useOnDeviceRecognition結果が「A」である場合、現在のデバイス、OSバージョン、言語設定で利用できる新しいデバイス上のパスが利用可能です。 true 結果が「B」である場合、デバイスは新しい認識パスをサポートしていません。

結果が「C」である場合、デバイスは新しい認識パスをサポートしていません。 false 結果が「D」である場合、デバイスは新しい認識パスをサポートしていません。

Platform SDK docs: iOS: 結果が「F」である場合、デバイスは新しい認識パスをサポートしていません。 結果が「G」である場合、デバイスは新しい認識パスをサポートしていません。 結果が「H」である場合、デバイスは新しい認識パスをサポートしていません。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.isOnDeviceRecognitionAvailable();

音声の収集と会話の文字起こしを開始します。

partialResults 」は、 true」が返される約束が即座に解決され、セッションが終了するまでの間は partialResults 」リスナーを通じて更新がストリーミングされます。

デフォルトのパスは、後方互換性のためにレガシーリコGNIZERの動作を維持します。 パス useOnDeviceRecognition: true 」を渡す前に、 を確認してください。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.start();

リスニングを停止し、ネイティブリソースを解体します。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.stop();

現在のセッションを強制終了します。

Androidでは、通常の停止を試みてからdestroy/recreateにフォールバックします。 timeoutiOSでは、現在のセッションを即座に停止します。

キャッシュされた部分のトランスクリプトがあれば、リスナーに"__CAPGO_KEEP_0__"で送信されます。 partialResults コピー forced: true.

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.forceStop();

コピー

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.getLastPartialResult();

この機能を使用するには

__CAPGO_KEEP_0__ continuousPTT またはカスタムのホールドトゥークフローと一緒に。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.setPTTState({} as PTTStateOptions);

認識エンジンがサポートするロケールを取得します。

Android 13+ デバイスでは、このリストは公開されなくなりました。そうでない場合 languages 空です。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.getSupportedLanguages();

プラグインが音声認識を実行しているかどうかを確認します。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.isListening();

現在の許可状態を取得します。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.checkPermissions();

requestPermissions

__CAPGO_KEEP_1__

__CAPGO_KEEP_2__

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.requestPermissions();

__CAPGO_KEEP_3__

__CAPGO_KEEP_1__

SpeechRecognitionAvailability

__CAPGO_KEEP_4__
export interface SpeechRecognitionAvailability {
available: boolean;
}

SpeechRecognitionStartOptions

__CAPGO_KEEP_5__

__CAPGO_KEEP_6__

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

__CAPGO_KEEP_7__
export interface SpeechRecognitionMatches {
matches?: string[];
}

のオプション

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;
}

の結果

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[];
}

のオプション

export interface PTTStateOptions {
/**
* Whether the PTT button is currently held.
*/
held: boolean;
}
export interface SpeechRecognitionLanguages {
languages: string[];
}
export interface SpeechRecognitionListening {
listening: boolean;
}

__CAPGO_KEEP_0__によって返される許可マップ checkPermissions そして requestPermissions.

export interface SpeechRecognitionPermissionStatus {
speechRecognition: PermissionState;
}

Androidのみで、セグメントされた結果が生成されたときに発生します。

export interface SpeechRecognitionSegmentResultEvent {
matches: string[];
}

部分的なトランスクリプションが生成されたときに発生します。

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;
}

リスニング状態が変化したときに発生します。

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';
}

このページはプラグインの src/definitions.ts. 公開APIがアップストリームで変更されたときに再度Syncを実行してください。