@capgo/capacitor-speech-synthesis 사용하기
텍스트를 음성으로 변환하는 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()
텍스트를 오디오 파일로 합성합니다 (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();
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.remove() 화면이 언마운트될 때, 또는 SpeechSynthesis.removeAllListeners() 모든 리스너를 해제하려면.
전체 레퍼런스
@capgo/capacitor-speech-synthesis 사용 계속하기
사용 중이라면 @capgo/capacitor-speech-synthesis 사용하기 네이티브 플러그인 작업을 계획하려면, 이를 다음 항목과 연결하세요: @capgo/capacitor-speech-synthesis @capgo/capacitor-speech-synthesis의 구현 상세 내용은 시작하기 Getting Started의 구현 상세 내용은 Capgo 플러그인 디렉토리 Capgo Plugin Directory의 제품 워크플로우에 맞춰, Capgo의 Capacitor 플러그인 Capgo의 Capacitor Plugins 구현 세부 사항 및 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트의 구현 세부 사항은.