Lompat ke konten

Mulai Membuat

GitHub

Anda dapat menggunakan Pengaturan Setup Bantuan AI untuk menginstal plugin. Tambahkan Capgo kemampuan ke alat AI Anda menggunakan perintah berikut:

Jendela terminal
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Lalu gunakan prompt berikut:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-speech-recognition` plugin in my project.

Jika Anda lebih suka Manual Setup, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah ini:

Jendela terminal
bun add @capgo/capacitor-speech-recognition
bunx cap sync
import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';

Mengecek apakah layanan pengenalan suara asli dapat digunakan pada perangkat saat ini.

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

Mengecek apakah jalur pengenalan suara asli yang lebih baru pada perangkat dapat digunakan untuk lokasi yang dipilih.

Ini adalah pengecekan kemampuan yang harus digunakan sebelum mengaktifkan useOnDeviceRecognitionHasilnya berarti perangkat, versi OS, dan lokasi saat ini dapat menggunakan jalur yang lebih baru untuk platform tersebut. true Kembali

Ketika perangkat hanya mendukung jalur recognizer yang lebih lama. false Dokumen __CAPGO_KEEP_0__ platform:

Platform SDK docs: iOS: Suara Android: Pengenalan Suara

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

Mengambil audio dan menerjemahkan percakapan.

Ketika partialResults adalah true, maka promise yang dikembalikan segera diselesaikan dan perubahan streamed melalui partialResults pengguna hingga sesi berakhir.

Jalan default menjaga perilaku pengenalan suara lama untuk konsistensi ke belakang. Lampirkan useOnDeviceRecognition: true hanya setelah memeriksa .

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

Menghentikan mendengarkan dan menurunkan sumber daya asli.

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

Menghentikan paksa sesi saat ini.

Pada Android, hal ini pertama mencoba menghentikan normal dan kemudian kembali ke destroy/recreate setelah timeout. Pada iOS, sesi saat ini dihentikan langsung.

Jika transkripsi parsial disimpan, maka akan dikeluarkan melalui partialResults pengguna dengan forced: true.

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

Mendapatkan hasil transkripsi parsial yang disimpan terakhir.

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

Mengupdate status tombol bicara ke depan saat ini.

Gunakan bersama dengan continuousPTT atau dengan alur tahan bicara yang disesuaikan.

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

Mengembalikan daftar bahasa yang didukung oleh pengenalan suara yang tersembunyi.

Perangkat Android 13+ tidak lagi menampilkan daftar ini; dalam kasus tersebut languages kosong.

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

Mengembalikan apakah plugin aktif mendengarkan suara.

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

Mendapatkan status izin saat ini.

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

Mengajukan izin mikrofon + pengenalan suara.

import { SpeechRecognition } from '@capgo/capacitor-speech-recognition';
await SpeechRecognition.requestPermissions();
export interface SpeechRecognitionAvailability {
available: boolean;
}

SpeechRecognitionStartOptions

Bagian berjudul “Opsi Pengenalan Suara”

Konfigurasi cara pengenalan suara berperilaku ketika memanggil .

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;
}
export interface SpeechRecognitionMatches {
matches?: string[];
}

Opsi untuk .

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

Hasil dari .

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

Opsi untuk .

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

Peta izin yang dikembalikan oleh checkPermissions dan requestPermissions.

export interface SpeechRecognitionPermissionStatus {
speechRecognition: PermissionState;
}

Ditinggalkan ketika hasil segmentasi diproduksi (hanya Android).

export interface SpeechRecognitionSegmentResultEvent {
matches: string[];
}

Ditimbulkan ketika transkripsi parsial diproduksi.

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

Ditimbulkan ketika status mendengarkan berubah.

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

Halaman ini dihasilkan dari plugin’s. src/definitions.tsRe-run sinkronisasi ketika publik API berubah di atas.

Jika Anda menggunakan Mulai untuk merencanakan dashboard dan API operasi, hubungkannya dengan Menggunakan @capgo/capacitor-pengenalan-suara untuk kemampuan asli dalam Menggunakan @capgo/capacitor-pengenalan-suara, API Ringkasan untuk detail implementasi dalam API Ringkasan, Pendahuluan untuk detail implementasi dalam Pendahuluan, API Kunci untuk detail implementasi dalam API Kunci, dan Perangkat untuk detail implementasi di Perangkat.