Guide
How to use Speech Synthesis in Capacitor
@capgo/capacitor-speech-synthesis 사용
텍스트에서 음성으로 합성하는 음성 합성 플러그인
설치
bun add @capgo/capacitor-speech-synthesis
bunx cap sync
bunx cap sync 플러그인의 네이티브 code을 프로젝트에 복사합니다. 플러그인 업그레이드 후 다시 실행하세요.
임포트
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
API의 개요
| 방법 | 설명 |
|---|---|
speak |
지정된 옵션으로 주어진 텍스트를 말합니다. 발화는 음성 큐에 추가됩니다. |
synthesizeToFile |
음성 파일로 음성 합성을 생성합니다 (Android/iOS만). 반환되는 파일 경로는 음성이 저장된 위치입니다. |
cancel |
음성 큐에 추가된 모든 발화를 취소하고 현재 음성을 중단합니다. |
pause |
음성을 즉시 중단합니다. |
resume |
중단된 음성을 재개합니다. |
isSpeaking |
현재 음성이 음성 합성을 하는지 확인합니다. |
isAvailable |
장치에서 음성 합성이 사용 가능한지 확인합니다. |
getVoices |
사용 가능한 모든 음성 출력을 가져옵니다. |
getLanguages |
사용 가능한 모든 언어를 가져옵니다. |
isLanguageAvailable |
특정 언어가 사용 가능한지 확인합니다. |
isVoiceAvailable |
특정 음성 출력이 사용 가능한지 확인합니다. |
initialize |
iOS 최적화를 위한 음성 합성 엔진을 초기화합니다. 첫 번째 음성 요청을 위해 지연 시간을 줄일 수 있습니다. |
activateAudioSession |
iOS에서만 특정 카테고리와 함께 오디오 세션을 활성화합니다. |
deactivateAudioSession |
iOS에서만 오디오 세션을 비활성화합니다. |
예시
speak()
음성 합성 엔진을 활성화합니다.
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()
지정된 옵션으로 주어진 텍스트를 말합니다. 음성 큐에 음성 발화가 추가됩니다.
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()
음성 합성을 위한 오디오 파일을 합성합니다. (Android/iOS에서만). 오디오 파일이 저장된 경로를 반환합니다.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.cancel();
pause()
음성 큐에 있는 모든 발화와 현재 음성 발화를 취소합니다.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.pause();
resume()
음성 발화를 즉시 중지합니다.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
await SpeechSynthesis.resume();
isSpeaking()
중단된 음성 발화를 재개합니다.
import { SpeechSynthesis } from '@capgo/capacitor-speech-synthesis';
const { isSpeaking } = await SpeechSynthesis.isSpeaking();
console.log('Is speaking:', isSpeaking);
현재 음성 발화 중인지 여부를 확인합니다. 위 표에는 14 개의 핵심 메소드가 있습니다. 리스너와 버전 도우미, 각 메소드의 전체 계약은 GitHub 저장소에서 문서화되어 있습니다..
이벤트를 들으세요
addListener handle을 반환합니다. Call handle.remove() 화면이 언마운트되면 또는 SpeechSynthesis.removeAllListeners() 모든 리스너를 지우려면
전체 참조
@capgo/capacitor-speech-synthesis
Using @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-speech-synthesis @capgo/capacitor-speech-synthesis native 플러그인 작업을 계획하려면 연결하세요 @capgo/capacitor-speech-synthesis @capgo/capacitor 음성 합성 시작하기 Getting Started 구현 세부 사항 Capgo 플러그인 디렉토리 Capgo 플러그인 디렉토리에서 제품 워크플로우 Capacitor Capgo 플러그인 for Capacitor 구현 세부사항에 대한 Capgo 플러그인에 의해 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트 구현 세부 사항