안내서
음성 합성에 대한 튜토리얼
Using @capgo/capacitor-speech-synthesis
음성 합성 플러그인: 텍스트에서 음성을 합성하는 데 사용됩니다.
설치
bun add @capgo/capacitor-speech-synthesis
bunx cap sync
이 플러그인이 노출하는 것
speak- 지정된 옵션과 함께 주어진 텍스트를 말합니다. 음성 큐에 음성이 추가됩니다.synthesizeToFile- Android/iOS에서만 음성을 파일로 합성합니다. 음성이 저장된 파일 경로를 반환합니다.cancel- 큐에 추가된 모든 음성을 취소하고 현재 음성을 중지합니다.pause- 즉시 말하기를 중단합니다.
예시 사용
speak
__CAPGO_KEEP_0__에 지정된 옵션과 함께 주어진 텍스트를 말합니다. 말하기 큐에 발화가 추가됩니다.
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
음성 파일로 말하기를 합성합니다 (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);
cancel
모든 큐된 발화와 현재 말하기를 취소합니다.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.cancel();
pause
즉시 말하기를 중단합니다.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.pause();
전체 참조
- GitHub: https://github.com/Cap-go/capacitor-speech-synthesis/
- 문서: /docs/plugins/speech-synthesis/