Panduan Memulai
Copy prompt setup berisi langkah install 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.
Anda bisa menggunakan AI-Assisted Setup untuk menginstal plugin ini. Tambahkan skill Capgo ke tool 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 Manual Setup, instal plugin dengan menjalankan perintah berikut dan ikuti instruksi khusus platform di bawah ini:
bun add @capgo/capacitor-speech-synthesisbunx cap syncimport { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';Mulai cepat
Bagian berjudul “Mulai cepat”import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.speak({ text: 'Gate B12 is boarding.', language: 'en-US', rate: 1.0,});Contoh: ekspor audio di native
Bagian berjudul “Contoh: ekspor audio di native”const { uri } = await SpeechSynthesis.synthesizeToFile({ text: lessonScript, language: 'es-ES',});Masalah umum
Bagian berjudul “Kesalahan umum”- Inisialisasi iOS: panggil
initialize()di awal pada iOS untuk mengurangi latensi bicara pertama. - Sesi audio: gunakan
activateAudioSession()saat suara harus mengecil atau bercampur dengan audio lain. - Suara web: daftar suara berbeda di tiap browser, selalu gunakan fallback ke suara default.
Ikhtisar API
Bagian berjudul “Ikhtisar API”Mengucapkan teks yang diberikan dengan opsi tertentu. Utterance akan ditambahkan ke antrean speech.
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
Bagian berjudul “synthesizeToFile”Mensintesis ucapan ke dalam file audio (hanya Android/iOS).\nMengembalikan path file tempat audio 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
Bagian berjudul “cancel”Membatalkan semua ujaran yang diantrekan dan menghentikan ucapan saat ini.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.cancel();Menjeda ucapan segera.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.pause();resume
Bagian berjudul “resume”Melanjutkan ucapan yang dijeda.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.resume();isSpeaking
Bagian berjudul “isSpeaking”Memeriksa apakah speech synthesis sedang berbicara.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isSpeaking } = await SpeechSynthesis.isSpeaking();console.log('Is speaking:', isSpeaking);isAvailable
Bagian berjudul “isAvailable”Mengecek apakah speech synthesis tersedia di perangkat.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isAvailable();if (isAvailable) { console.log('Speech synthesis is available');}getVoices
Bagian berjudul “getVoices”Mengambil semua voice 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 speech synthesis engine (optimasi iOS). Ini dapat mengurangi latensi pada request suara pertama.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.initialize();activateAudioSession
Bagian berjudul “activateAudioSession”Mengaktifkan audio session dengan kategori tertentu (khusus iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.activateAudioSession({ category: 'Playback'});deactivateAudioSession
Bagian berjudul “deactivateAudioSession”Menonaktifkan audio session (khusus iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.deactivateAudioSession();Referensi Tipe
Bagian berjudul “Type Reference”SpeakOptions
Bagian berjudul “SpeakOptions”Opsi untuk membacakan 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
Bagian berjudul “SpeakResult”Hasil dari pembacaan teks.
export interface SpeakResult { /** * Unique identifier for this utterance. * * @since 1.0.0 */ utteranceId: string;}SynthesizeToFileResult
Bagian berjudul “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
Bagian berjudul “VoiceInfo”Informasi mengenai 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
Bagian berjudul “IsLanguageAvailableOptions”Opsi untuk mengecek ketersediaan bahasa.
export interface IsLanguageAvailableOptions { /** * The BCP-47 language code to check. * * @since 1.0.0 */ language: string;}IsVoiceAvailableOptions
Bagian berjudul “IsVoiceAvailableOptions”Opsi untuk mengecek ketersediaan suara.
export interface IsVoiceAvailableOptions { /** * The voice ID to check. * * @since 1.0.0 */ voiceId: string;}ActivateAudioSessionOptions
Bagian berjudul “ActivateAudioSessionOptions”Opsi untuk mengaktifkan audio session (khusus 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
Bagian berjudul “UtteranceEvent”Event yang dipicu saat ucapan dimulai atau berakhir.
export interface UtteranceEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;}BoundaryEvent
Bagian berjudul “BoundaryEvent”Event yang dipicu 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
Bagian berjudul “ErrorEvent”Event yang dipicu saat terjadi error sintesis.
export interface ErrorEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;
/** * The error message. * * @since 1.0.0 */ error: string;}Sumber Kebenaran
Bagian berjudul “Sumber Kebenaran”Halaman ini dibuat dari plugin src/definitions.ts. Jalankan ulang sync saat API publik berubah di upstream.
Lanjutkan dari Getting Started
Bagian berjudul “Lanjutkan dari Getting Started”Jika Anda menggunakan Panduan Memulai untuk merencanakan operasi dashboard dan API, hubungkan dengan Menggunakan @capgo/capacitor-speech-synthesis untuk kapabilitas native di Menggunakan @capgo/capacitor-speech-synthesis, Ikhtisar API untuk detail implementasi di Ringkasan API, Pendahuluan untuk detail implementasi di Pendahuluan, Kunci API untuk detail implementasi di API Keys, dan Perangkat untuk detail implementasi di Perangkat.