Getting Started
Copas prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-speech-synthesis`
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-synthesis/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.
Install
Bagian berjudul “Install”Anda dapat menggunakan Setup Bantuan AI kami untuk menginstal plugin ini. Tambahkan Capgo kemampuan ke alat AI Anda menggunakan perintah berikut:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsLalu gunakan prompt berikut:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-speech-synthesis` plugin in my project.Jika Anda lebih suka Setup Manual, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah ini:
bun add @capgo/capacitor-speech-synthesisbunx cap syncImport
Bagian berjudul “Import”import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';API Ringkasan
Judul Bagian “API Pengantar”Mengucapkan teks yang diberikan dengan pilihan yang ditentukan. Ucapan ditambahkan ke antrian bicara.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const result = await SpeechSynthesis.speak({ text: 'Hello, world!', language: 'en-US', rate: 1.0, pitch: 1.0, volume: 1.0, queueStrategy: 'Add'});console.log('Utterance ID:', result.utteranceId);synthesizeToFile
Judul Bagian “synthesizeToFile”Menghasilkan suara bicara ke dalam file audio (hanya Android/iOS). Mengembalikan jalur file tempat suara disimpan.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const result = await SpeechSynthesis.synthesizeToFile({ text: 'Hello, world!', language: 'en-US'});console.log('Audio file saved at:', result.filePath);cancel
Judul Bagian “batal”Membatalkan semua ucapan yang ditunggu dan menghentikan bicara saat ini.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.cancel();Menghentikan bicara segera.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.pause();resume
Bab berjudul “resume”Menunda pembicaraan yang berlangsung.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.resume();isSpeaking
Bab berjudul “isSpeaking”Memeriksa apakah sintesis suara sedang berbicara.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isSpeaking } = await SpeechSynthesis.isSpeaking();console.log('Is speaking:', isSpeaking);isAvailable
Bab berjudul “isAvailable”Memeriksa apakah sintesis suara tersedia di perangkat.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isAvailable();if (isAvailable) { console.log('Speech synthesis is available');}getVoices
Bab berjudul “getVoices”Mengambil semua suara yang tersedia.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { voices } = await SpeechSynthesis.getVoices();voices.forEach(voice => { console.log(`${voice.name} (${voice.language})`);});getLanguages
Bagian berjudul “getLanguages”Mengambil semua bahasa yang tersedia.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { languages } = await SpeechSynthesis.getLanguages();console.log('Available languages:', languages);isLanguageAvailable
Bagian berjudul “isLanguageAvailable”Mengecek apakah bahasa tertentu tersedia.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isLanguageAvailable({ language: 'es-ES'});console.log('Spanish available:', isAvailable);isVoiceAvailable
Bagian berjudul “isVoiceAvailable”Mengecek apakah suara tertentu tersedia.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isVoiceAvailable({ voiceId: 'com.apple.ttsbundle.Samantha-compact'});console.log('Voice available:', isAvailable);initialize
Bagian berjudul “initialize”Menginisialisasi mesin sintesis suara (optimasi iOS). Hal ini dapat mengurangi latency untuk permintaan suara pertama.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.initialize();activateAudioSession
Bagian berjudul “aktifkanSesiAudio”Mengaktifkan sesi audio dengan kategori tertentu (hanya iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.activateAudioSession({ category: 'Playback'});deactivateAudioSession
Bagian berjudul “nonaktifkanSesiAudio”Mengnonaktifkan sesi audio (hanya iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.deactivateAudioSession();Referensi Tipe
Bagian berjudul “Referensi Tipe”SpeakOptions
Bagian berjudul “PilihanBerbicara”Pilihan untuk berbicara teks.
export interface SpeakOptions { /** * The text to speak. * * @since 1.0.0 */ text: string;
/** * The BCP-47 language tag (e.g., 'en-US', 'es-ES'). * * @since 1.0.0 */ language?: string;
/** * The voice identifier to use. * * @since 1.0.0 */ voiceId?: string;
/** * The pitch of the voice (0.5 to 2.0, default: 1.0). * * @since 1.0.0 */ pitch?: number;
/** * The speaking rate (0.1 to 10.0, default: 1.0). * * @since 1.0.0 */ rate?: number;
/** * The volume (0.0 to 1.0, default: 1.0). * * @since 1.0.0 */ volume?: number;
/** * The queue strategy: 'Add' to append or 'Flush' to replace queue. * Default: 'Add' * * @since 1.0.0 */ queueStrategy?: 'Add' | 'Flush';}SpeakResult
Judul Bagian “SpeakResult”Hasil dari teks yang dibacakan.
export interface SpeakResult { /** * Unique identifier for this utterance. * * @since 1.0.0 */ utteranceId: string;}SynthesizeToFileResult
Judul Bagian “SynthesizeToFileResult”Hasil dari sintesis ke file.
export interface SynthesizeToFileResult { /** * The file path where audio was saved. * * @since 1.0.0 */ filePath: string;
/** * Unique identifier for this utterance. * * @since 1.0.0 */ utteranceId: string;}VoiceInfo
Judul Bagian “VoiceInfo”Informasi tentang suara.
export interface VoiceInfo { /** * Unique voice identifier. * * @since 1.0.0 */ id: string;
/** * Display name of the voice. * * @since 1.0.0 */ name: string;
/** * BCP-47 language code. * * @since 1.0.0 */ language: string;
/** * Gender of the voice (iOS only). * * @since 1.0.0 */ gender?: 'male' | 'female' | 'neutral';
/** * Whether this voice requires a network connection. * * @since 1.0.0 */ isNetworkConnectionRequired?: boolean;
/** * Whether this is the default voice (Web only). * * @since 1.0.0 */ default?: boolean;}IsLanguageAvailableOptions
Judul Bagian “IsLanguageAvailableOptions”Opsi untuk memeriksa ketersediaan bahasa.
export interface IsLanguageAvailableOptions { /** * The BCP-47 language code to check. * * @since 1.0.0 */ language: string;}IsVoiceAvailableOptions
Pengaturan Judul “IsVoiceAvailableOptions”Pilihan untuk memeriksa ketersediaan suara.
export interface IsVoiceAvailableOptions { /** * The voice ID to check. * * @since 1.0.0 */ voiceId: string;}ActivateAudioSessionOptions
Pengaturan Judul “Aktifkan Sesion Audio Options”Pilihan untuk mengaktifkan sesi audio (hanya iOS).
export interface ActivateAudioSessionOptions { /** * The audio session category. * - 'Ambient': Mixes with other audio * - 'Playback': Stops other audio * * @since 1.0.0 */ category: 'Ambient' | 'Playback';}UtteranceEvent
Pengaturan Judul “UtteranceEvent”Event yang dipancarkan ketika ucapan dimulai atau berakhir.
export interface UtteranceEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;}BoundaryEvent
Pengaturan Judul “BoundaryEvent”Event yang dipancarkan pada batas kata.
export interface BoundaryEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;
/** * The character index in the text. * * @since 1.0.0 */ charIndex: number;
/** * The character length of the current word. * * @since 1.0.0 */ charLength?: number;}ErrorEvent
Judul Bagian “ErrorEvent”Event yang dikeluarkan ketika terjadi kesalahan sintesis.
export interface ErrorEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;
/** * The error message. * * @since 1.0.0 */ error: string;}Sumber Kebenaran
Judul Bagian “Sumber Kebenaran”Halaman ini dihasilkan dari plugin’s. Re-run sinkronisasi ketika __CAPGO_KEEP_0__ publik berubah di atas. src/definitions.ts. Re-run the sync when the public API changes upstream.
Judul Bagian “Lanjutkan dari Getting Started”
Jika Anda menggunakanGetting Started untuk merencanakan dashboard dan __CAPGO_KEEP_0__ operasi, hubungkannya dengan to plan dashboard and API operations, connect it with Menggunakan @capgo/capacitor-speech-synthesis untuk kemampuan asli di Menggunakan @capgo/capacitor-speech-synthesis, API Ringkasan untuk detail implementasi di API Ringkasan, Pendahuluan untuk detail implementasi di Pendahuluan, API Kunci untuk detail implementasi di API Kunci, dan Perangkat untuk detail implementasi di Perangkat.