Getting Started
Copia un prompt di configurazione con i passaggi di installazione e la guida markdown completa per questo plugin.
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.
Installare
Sezione intitolata “Installare”Puoi utilizzare la nostra configurazione assistita dall'IA per installare il plugin. Aggiungi le Capgo abilità al tuo strumento di IA utilizzando il seguente comando:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsPoi utilizza la seguente richiesta:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-speech-synthesis` plugin in my project.Se preferisci l'installazione manuale, installa il plugin eseguendo i seguenti comandi e segui le istruzioni specifiche per la piattaforma riportate di seguito.
bun add @capgo/capacitor-speech-synthesisbunx cap syncimport { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';Sottosezione intitolata “API Overview”
Section titled “API Overview”Parla il testo specificato con le opzioni specificate. L'intera frase viene aggiunta alla coda di sintesi vocale.
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
Sottosezione intitolata “speak”Sintetizza la parlata in un file audio (solo Android/iOS). Restituisce la percorso del file dove è stato salvato l'audio.
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);Annulla tutte le frasi in coda e ferma la parlata corrente.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.cancel();Pausa la parlata immediatamente.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.pause();Riprende la parlata pausata.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.resume();isSpeaking
Sezione intitolata “Sta Parlare”Verifica se la sintesi vocale sta parlando attualmente.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isSpeaking } = await SpeechSynthesis.isSpeaking();console.log('Is speaking:', isSpeaking);isAvailable
Sezione intitolata “isAvailable”Verifica se la sintesi vocale è disponibile sul dispositivo.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isAvailable();if (isAvailable) { console.log('Speech synthesis is available');}getVoices
Sezione intitolata “getVoices”Ottiene tutte le voci disponibili.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { voices } = await SpeechSynthesis.getVoices();voices.forEach(voice => { console.log(`${voice.name} (${voice.language})`);});getLanguages
Sezione intitolata “getLanguages”Ottiene tutte le lingue disponibili.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { languages } = await SpeechSynthesis.getLanguages();console.log('Available languages:', languages);isLanguageAvailable
Sezione intitolata “isLanguageAvailable”Verifica se una specifica lingua è disponibile.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isLanguageAvailable({ language: 'es-ES'});console.log('Spanish available:', isAvailable);isVoiceAvailable
Sezione intitolata “isVoiceAvailable”Verifica se una specifica voce è disponibile.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isVoiceAvailable({ voiceId: 'com.apple.ttsbundle.Samantha-compact'});console.log('Voice available:', isAvailable);initialize
Sezione intitolata “initialize”Inizializza l'engine di sintesi vocale (ottimizzazione iOS). Ciò può ridurre la latenza per la prima richiesta di sintesi vocale.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.initialize();activateAudioSession
Sezione intitolata “activateAudioSession”Attiva la sessione audio con una specifica categoria (solo per iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.activateAudioSession({ category: 'Playback'});deactivateAudioSession
Sezione intitolata “deactivateAudioSession”Disabilita la sessione audio (solo per iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.deactivateAudioSession();Riferimento di tipo
Sezione intitolata “Riferimento di tipo”SpeakOptions
Sezione intitolata “Opzioni per parlare”Opzioni per parlare il testo.
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
Sezione intitolata “Risultato di parlato”Risultato dal parlato del testo.
export interface SpeakResult { /** * Unique identifier for this utterance. * * @since 1.0.0 */ utteranceId: string;}SynthesizeToFileResult
Sezione intitolata “Risultato di sintesi su file”Risultato dalla sintesi su 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
Sezione intitolata “VoiceInfo”Informazioni sulla voce.
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
Sezione intitolata “IsLanguageAvailableOptions”Opzioni per verificare la disponibilità della lingua.
export interface IsLanguageAvailableOptions { /** * The BCP-47 language code to check. * * @since 1.0.0 */ language: string;}IsVoiceAvailableOptions
Sezione intitolata “IsVoiceAvailableOptions”Opzioni per verificare la disponibilità della voce.
export interface IsVoiceAvailableOptions { /** * The voice ID to check. * * @since 1.0.0 */ voiceId: string;}ActivateAudioSessionOptions
Sezione intitolata “ActivateAudioSessionOptions”Opzioni per attivare la sessione audio (solo per 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
Sezione intitolata “UtteranceEvent”Evento emesso quando l'utterance inizia o termina.
export interface UtteranceEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;}BoundaryEvent
Sezione intitolata “BoundaryEvent”Evento emesso ai confini delle parole.
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
Sezione intitolata “ErrorEvent”Evento emesso in caso di errore di sintesi.
export interface ErrorEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;
/** * The error message. * * @since 1.0.0 */ error: string;}Fonte di Verità
Sezione intitolata “Fonte di Verità”Questa pagina è generata dal plugin's src/definitions.tsRieccere lo sync quando le modifiche pubbliche API cambiano in alto flusso.
Keep going from Getting Started
Sezione intitolata “Prosegui da Inizia”Se stai utilizzando Getting Started per pianificare dashboard e API operazioni, connettilo con Utilizza @capgo/capacitor-speech-synthesis per la capacità nativa in Utilizza @capgo/capacitor-speech-synthesis, API Overview per la dettagliata implementazione in API Overview, Introduzione per i dettagli di implementazione in Introduzione API Chiavi per i dettagli di implementazione in API Chiavi, e Dispositivi Per i dettagli di implementazione nei dispositivi.