__CAPGO_KEEP_5__

はじめに

GitHub

インストール

インストール

CapgoのAIアシストのセットアップを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを実行してください。

ターミナル画面
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Capgoのマーケティングウェブサイトのページエージェント/[スラッグ].astroのUIラベル。メッセージキー`agents_page_copy_label` (エージェントページコピーラベル)。

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-recognition
npx 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: not supported; use a browser speech API separately if you need Web-only dictation.

現在のデバイス上のネイティブ スピーチ認識サービスが利用可能かどうかを確認します。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.available();
console.log(result);

isOnDeviceRecognitionAvailable

デバイス内認識が利用可能か

セクション「isOnDeviceRecognitionAvailable」

この機能を有効にする前に使用する必要がある機能チェックです。 useOnDeviceRecognition。 A true 結果は、現在のデバイス、OSバージョン、ロケールが新しいデバイスパスを使用できることを意味します。

返します。 false デバイスがレガシーパス認識器のみをサポートしている場合。

プラットフォーム SDK ドキュメント: iOS: Speech Android:

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.isOnDeviceRecognitionAvailable();
console.log(result);

「start」セクション

When partialResults は true、 partialResults 返却されるプロミスは即時解決され、更新はセッション終了まで

リスナーよりストリーミングされます。 useOnDeviceRecognition: true デフォルトのパスは、後方互換性のためにレガシーリコgnizerの動作を維持します。 パス

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.start();
console.log(result);

stop

のみ

で確認した後

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

forceStop

コピー

コピーするにはクリップボードにコピーしてください。

On Android, この最初に正常停止を試みて、次に破棄/再作成にフォールバックします。 timeoutOn iOS, では現在のセッションは即座に停止されます。

キャッシュされている部分トランスクリプトがあれば、リスナーに次のように送信されます。 partialResults コピー forced: true.

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

「setPTTState」セクション

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.getLastPartialResult();
console.log(result);

この機能を使用して、またはカスタムのホールド・トゥ・トークフローと組み合わせてください。

コピー continuousPTT 「getLastPartialResult」セクション

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.setPTTState({ held: true });

サポートする言語を取得します。

Android 13以降のデバイスでは、このリストは公開されなくなります。その場合 languages 空のリストになります。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.getSupportedLanguages();
console.log(result);

プラグインが音声を受信しているかどうかを返します。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.isListening();
console.log(result);

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

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.checkPermissions();
console.log(result);

マイク + 会話認識の権限を要求します。

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
const result = await SpeechRecognition.requestPermissions();
console.log(result);

SpeechRecognitionAvailability

会話認識の利用可能性
export interface SpeechRecognitionAvailability {
available: boolean;
}

認識器の動作を設定します。

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

会話認識のマッチング
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;
}

Capacitor によって返される許可マップ 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再度Syncを実行してください。public APIがアップストリームで変更されたとき。

Getting Startedから続けてください。

「Getting Startedから続けてください。」

Capgoを使用している場合 スタートガイド 計画ダッシュボードとAPIの運用を計画し、 @capgo/capacitor-speech-recognition native capability in @capgo/capacitor-speech-recognition について API の概要 API の実装詳細について 導入 __CAPGO_KEEP_0__ の実装詳細について API のキー API の実装詳細について、 デバイス __CAPGO_KEEP_0__ の実装詳細について