Getting Started
Kopieren Sie einen Setup-Vorschlag mit den Installationsanweisungen und der vollständigen Markdown-Anleitung für diesen 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.
Installieren
Abschnitt mit dem Titel “Installieren”Sie können unser AI-gestütztes Setup verwenden, um das Plugin zu installieren. Fügen Sie die Capgo-Fähigkeiten mit dem folgenden Befehl in Ihre AI-Anwendung ein:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsVerwenden Sie dann die folgende Anweisung:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-speech-synthesis` plugin in my project.Wenn Sie die manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und die darunter angegebenen Plattform-spezifischen Anweisungen befolgen.
bun add @capgo/capacitor-speech-synthesisbunx cap syncImportieren
Abschnitt mit dem Titel „Importieren“import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';API Übersicht
Abschnitt mit dem Titel „API Übersicht“Sprechen Sie den angegebenen Text mit angegebenen Optionen. Die Aussage wird der Sprechwarte hinzugefügt.
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
Sektion mit Titel ‘zum Dateispeicher schreiben’Synthesisiert Sprache in ein Audio-File (nur Android/iOS). Gibt den Dateipfad zurück, an dem das Audio gespeichert wurde.
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);Beendet alle geplante Aussagen und stoppt die aktuelle Sprache.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.cancel();Sprache sofort pausieren.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.pause();Sprachausgabe wird unterbrochen.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.resume();isSpeaking
Abschnitt mit dem Titel “sprecht”Überprüft, ob die Sprachsynthese gerade spricht.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isSpeaking } = await SpeechSynthesis.isSpeaking();console.log('Is speaking:', isSpeaking);isAvailable
Abschnitt mit dem Titel “verfügbar”Überprüft, ob die Sprachsynthese auf dem Gerät verfügbar ist.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isAvailable();if (isAvailable) { console.log('Speech synthesis is available');}getVoices
Abschnitt mit dem Titel “stimmen”Alle verfügbaren Stimmen abrufen.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { voices } = await SpeechSynthesis.getVoices();voices.forEach(voice => { console.log(`${voice.name} (${voice.language})`);});getLanguages
Abschnitt mit dem Titel “getLanguages”Alle verfügbaren Sprachen abrufen.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { languages } = await SpeechSynthesis.getLanguages();console.log('Available languages:', languages);isLanguageAvailable
Abschnitt mit dem Titel “isLanguageAvailable”Überprüft, ob eine bestimmte Sprache verfügbar ist.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isLanguageAvailable({ language: 'es-ES'});console.log('Spanish available:', isAvailable);isVoiceAvailable
Abschnitt mit dem Titel “isVoiceAvailable”Überprüft, ob eine bestimmte Stimme verfügbar ist.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isVoiceAvailable({ voiceId: 'com.apple.ttsbundle.Samantha-compact'});console.log('Voice available:', isAvailable);initialize
Abschnitt mit dem Titel “initialize”Initialisiert den Sprachsynthesizer (iOS-Optimierung). Dies kann die Latenz für den ersten Sprachanforderung reduzieren.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.initialize();activateAudioSession
Abschnitt mit dem Titel “Audio-Sitzung aktivieren”Aktiviert die Audio-Sitzung mit einer bestimmten Kategorie (nur iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.activateAudioSession({ category: 'Playback'});deactivateAudioSession
Abschnitt mit dem Titel “Audio-Sitzung deaktivieren”Deaktiviert die Audio-Sitzung (nur iOS).
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.deactivateAudioSession();Typenreferenz
Abschnitt mit dem Titel “Typenreferenz”SpeakOptions
Abschnitt mit dem Titel “Sprechoptionen”Sprechoptionen für Text.
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
Abschnitt mit dem Titel “Sprechergebnis”Ergebnis aus dem Sprechen von Text.
export interface SpeakResult { /** * Unique identifier for this utterance. * * @since 1.0.0 */ utteranceId: string;}SynthesizeToFileResult
Abschnitt mit dem Titel “ZusammenfassungInDateiResult”Ergebnis aus der Synthese in eine Datei.
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;}Informationen über eine Stimme.
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
Abschnitt mit dem Titel “Sprachverfügbarkeitsoptionen”Optionen für die Überprüfung der Sprachverfügbarkeit.
export interface IsLanguageAvailableOptions { /** * The BCP-47 language code to check. * * @since 1.0.0 */ language: string;}IsVoiceAvailableOptions
Abschnitt mit dem Titel “Stimmenverfügbarkeitsoptionen”Optionen für die Überprüfung der Stimmenverfügbarkeit.
export interface IsVoiceAvailableOptions { /** * The voice ID to check. * * @since 1.0.0 */ voiceId: string;}ActivateAudioSessionOptions
Abschnitt mit dem Titel „Aktivieren Sie Audio-Sitzungsoptionen“Optionen zum Aktivieren der Audio-Sitzung (nur 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
Abschnitt mit dem Titel „UtteranceEvent“Ereignis, das bei Beginn oder Ende der Aussage ausgelöst wird.
export interface UtteranceEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;}BoundaryEvent
Abschnitt mit dem Titel „BoundaryEvent“Ereignis, das bei Wortgrenzen ausgelöst wird.
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
Abschnitt mit dem Titel „ErrorEvent“Ereignis wird auf Synthese fehler ausgestrahlt.
export interface ErrorEvent { /** * The utterance identifier. * * @since 1.0.0 */ utteranceId: string;
/** * The error message. * * @since 1.0.0 */ error: string;}Quelle der Wahrheit
Abschnitt mit dem Titel “Quelle der Wahrheit”Diese Seite wird aus dem Plugin generiert. src/definitions.tsRe-run die Synchronisierung, wenn die öffentliche API upstream geändert wird.
Weitermachen von Getting Started
Abschnitt mit dem Titel “Weitermachen von Getting Started”Wenn Sie das Plugin verwenden Getting Started um das Dashboard und die API-Operationen zu planen, verbinden Sie es mit Mit @capgo/capacitor-speech-synthesis Für die native Fähigkeit in @capgo/capacitor-Sprachsynthese, API Übersicht Für die Implementierungsdetails in API Übersicht, Einführung Für die Implementierungsdetails in Einführung, API Schlüssel Für die Implementierungsdetails in API Schlüssel und Geräte Für die Implementierungsdetails in Geräte.