Inicio
Copie un comando de configuración con los pasos de instalación y la guía de markdown completa para este 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.
Instalar
Sección titulada “Instalar”bun add @capgo/capacitor-speech-synthesisbunx cap syncImportar
Sección titulada “Importar”import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';API Resumen
Sección titulada “API Resumen”Habla el texto dado con las opciones especificadas. La emisión se agrega a la cola de habla.
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
Sección titulada “synthesizetofile”Sintetiza el habla a un archivo de audio (solo Android/iOS). Devuelve la ruta del archivo donde se guardó el 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);Cancela todas las oraciones programadas y detiene la habla actual.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.cancel();Pausa la habla inmediatamente.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.pause();Reanuda la habla pausada.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.resume();isSpeaking
Sección titulada “estáHablando”Verifica si la síntesis de habla está hablando actualmente.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isSpeaking } = await SpeechSynthesis.isSpeaking();console.log('Is speaking:', isSpeaking);isAvailable
Sección titulada “isAvailable”Verifica si la síntesis de voz está disponible en el dispositivo.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isAvailable();if (isAvailable) { console.log('Speech synthesis is available');}getVoices
Sección titulada “getVoices”Obtiene todas las voces disponibles.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { voices } = await SpeechSynthesis.getVoices();voices.forEach(voice => { console.log(`${voice.name} (${voice.language})`);});getLanguages
Sección titulada “getLanguages”Obtiene todos los idiomas disponibles.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { languages } = await SpeechSynthesis.getLanguages();console.log('Available languages:', languages);isLanguageAvailable
Sección titulada “isLanguageAvailable”Verifica si un idioma específico está disponible.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isLanguageAvailable({ language: 'es-ES'});console.log('Spanish available:', isAvailable);isVoiceAvailable
Sección titulada “isVoiceAvailable”Verifica si una voz específica está disponible.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isVoiceAvailable({ voiceId: 'com.apple.ttsbundle.Samantha-compact'});console.log('Voice available:', isAvailable);initialize
Sección titulada “initialize”Inicia el motor de síntesis de habla (optimización de iOS). Esto puede reducir la latencia para la primera solicitud de habla.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.initialize();activateAudioSession
Sección titulada “activateAudioSession”Activa la sesión de audio con una categoría específica (solo iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.activateAudioSession({ category: 'Playback'});deactivateAudioSession
Sección titulada “deactivateAudioSession”Desactiva la sesión de audio (solo iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.deactivateAudioSession();Referencia de tipo
Sección titulada “Referencia de tipo”SpeakOptions
Sección titulada “Opciones de hablar”Opciones para hablar texto.
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
Sección titulada “Resultado de hablar”Resultado de hablar texto.
export interface SpeakResult { /** * Unique identifier for this utterance. * * @since 1.0.0 */ utteranceId: string;}SynthesizeToFileResult
Sección titulada “Resultado de sintetizar a archivo”Resultado de sintetizar a archivo.
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
Sección titulada “VoiceInfo”Información sobre una voz.
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
Sección titulada “IsLanguageAvailableOptions”Opciones para verificar la disponibilidad de idiomas.
export interface IsLanguageAvailableOptions { /** * The BCP-47 language code to check. * * @since 1.0.0 */ language: string;}IsVoiceAvailableOptions
Sección titulada “IsVoiceAvailableOptions”Opciones para verificar la disponibilidad de voces.
export interface IsVoiceAvailableOptions { /** * The voice ID to check. * * @since 1.0.0 */ voiceId: string;}ActivateAudioSessionOptions
Sección titulada “ActivateAudioSessionOptions”Opciones para activar la sesión de audio (solo 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
Sección titulada “UtteranceEvent”Evento emitido cuando comienza o termina la emisión de voz.
export interface UtteranceEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;}BoundaryEvent
Sección titulada “BoundaryEvent”Evento emitido en las fronteras de palabras.
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
Sección titulada “ErrorEvent”Evento emitido en caso de error de síntesis.
export interface ErrorEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;
/** * The error message. * * @since 1.0.0 */ error: string;}Fuente De Verdad
Sección titulada “Fuente De Verdad”Esta página se genera desde el plugin’s src/definitions.ts. Re-run la sincronización cuando el público API cambia en la fuente.
Sigue adelante desde Getting Started
Título de la sección “Sigue adelante desde Getting Started”Si estás utilizando Getting Started para planificar la consola de dashboard y API operaciones, conecta con Usando @capgo/capacitor-speech-synthesis para la capacidad nativa en Usando @capgo/capacitor-speech-synthesis API Overview para el detalle de implementación en API Overview Introducción para el detalle de implementación en Introducción API Claves para el detalle de implementación en API Claves, y Dispositivos para el detalle de implementación en Dispositivos.