__CAPGO_KEEP_2__

Getting Started

GitHub

CapgoのAIアシストセットアップを使用してプラグインをインストールできます。次のコマンドを使用して、CapgoスキルをAIツールに追加します。

ターミナルウィンドウ
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次のプロンプトを使用してください:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-speech-synthesis` plugin in my project.

Manual Setupを使用する場合は、以下のコマンドを実行して、下記のプラットフォーム固有の手順に従ってください。

ターミナルウィンドウ
bun add @capgo/capacitor-speech-synthesis
bunx cap sync
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';

指定されたオプションで与えられたテキストを話す。 話す内容は音声キューに追加されます。

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);

音声ファイルに合成する (Android/iOS 限定)。 音声ファイルの保存先のパスを返します。

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);

キュー内のすべての発話をキャンセルし、現在の音声を停止します。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.cancel();

音声の流れを即時停止します。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.pause();

話し言葉の再開が停止されます。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.resume();

話し言葉合成が現在話しているかどうかを確認します。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isSpeaking } = await SpeechSynthesis.isSpeaking();
console.log('Is speaking:', isSpeaking);

話し言葉合成がデバイスで利用可能かどうかを確認します。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isAvailable();
if (isAvailable) {
console.log('Speech synthesis is available');
}

利用可能なすべての声の取得

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { voices } = await SpeechSynthesis.getVoices();
voices.forEach(voice => {
console.log(`${voice.name} (${voice.language})`);
});

利用可能なすべての言語を取得します。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { languages } = await SpeechSynthesis.getLanguages();
console.log('Available languages:', languages);

特定の言語が利用可能かどうかを確認します。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isLanguageAvailable({
language: 'es-ES'
});
console.log('Spanish available:', isAvailable);

特定の声が利用可能かどうかを確認します。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isAvailable } = await SpeechSynthesis.isVoiceAvailable({
voiceId: 'com.apple.ttsbundle.Samantha-compact'
});
console.log('Voice available:', isAvailable);

iOSの最適化されたスピーチ合成エンジンを初期化します。 最初のスピーチリクエストの遅延を削減できます。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.initialize();

iOS専用。特定のカテゴリでオーディオセッションを有効にします。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.activateAudioSession({
category: 'Playback'
});

iOS専用。オーディオセッションを無効にします。

import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.deactivateAudioSession();

テキストを話すためのオプションです。

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';
}

テキストを話す結果

export interface SpeakResult {
/**
* Unique identifier for this utterance.
*
* @since 1.0.0
*/
utteranceId: string;
}

ファイルに合成する結果

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;
}

声の情報

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;
}

言語利用可能性のオプション

export interface IsLanguageAvailableOptions {
/**
* The BCP-47 language code to check.
*
* @since 1.0.0
*/
language: string;
}

声の利用可能性を確認するためのオプション。

export interface IsVoiceAvailableOptions {
/**
* The voice ID to check.
*
* @since 1.0.0
*/
voiceId: string;
}

オーディオセッションを有効にするためのオプション(iOSのみ)。

export interface ActivateAudioSessionOptions {
/**
* The audio session category.
* - 'Ambient': Mixes with other audio
* - 'Playback': Stops other audio
*
* @since 1.0.0
*/
category: 'Ambient' | 'Playback';
}

発話が始まるまたは終わる際に発生するイベント。

export interface UtteranceEvent {
/**
* The utterance identifier.
*
* @since 1.0.0
*/
utteranceId: string;
}

単語境界で発生するイベント。

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;
}

合成エラー発生時に発行されるイベント。

export interface ErrorEvent {
/**
* The utterance identifier.
*
* @since 1.0.0
*/
utteranceId: string;
/**
* The error message.
*
* @since 1.0.0
*/
error: string;
}

このページはプラグインの src/definitions.tsパブリックAPIがアップストリームで変更されたときに再度Syncを実行してください。

Getting Startedから続けてください

セクション「Getting Startedから続けてください」

あなたが Getting Started を使用してダッシュボードとAPIの作業を計画している場合、 Capacitor で使用する @capgo/capacitor-speech-synthesis Capacitor のネイティブ機能である @capgo/capacitor-speech-synthesis API の概要 Capacitor の実装詳細である API の概要 導入 Capacitor の実装詳細である導入 API のキー Capacitor の実装詳細である API のキー、 デバイス Capacitor の実装詳細であるデバイス