easy-tts
v0.2.0
Published
Lightweight TTS library for browsers.
Downloads
9
Readme
easy-tts
This package is meant to lighten the work around TTS in browsers. It's compatible for every browser because it calls Google Translate API as backup speech.
🟧 Warning The package works, but expect further updates with API changes.
Installation
npm i easy-tts
Usage
Basic
import { speak, listWords } from "easy-tts"
await speak({
lng: "en",
text: "Hey, hear my beautiful voice!",
voiceName: listWords("EN").filteredVoiceNames[0],
volume: 75,
});
Advenced
import { speak, GoogleVoiceName } from "easy-tts"
await speak({
lng: "en",
text: "Hey, hear my beautiful voice!",
voiceName: GoogleVoiceName, // sets the voice of Google Translate
volume: 75,
stopCurrentSpeech: false,
pitch: 1.5,
rate: 2, // 2x speed of voice
forceGoogleMinRate: 0.5,
forceGoogleMaxRate: 5
});
Google TTS
import { speak, listWords, GoogleVoiceName } from "easy-tts"
await speak({
lng: "en",
text: "Hey, hear my beautiful voice!",
voiceName: GoogleVoiceName,
volume: 75,
});
SpeechSynthesis Compatibility
Check whether or not the user's browser is capable of using built in TTS.
import { checkSpeechSynthesisCompatibility } from "easy-tts"
checkSpeechSynthesisCompatibility()
checkSpeechSynthesisCompatibility("en")
Pause, resume and cancel speech
import { cancelSpeech, resumeSpeech, pauseSpeech, speak } from "easy-tts";
speak({...})
pauseSpeech()
resumeSpeech()
speak({...})
cancelSpeech()
Examples
TODOS
- [x] Appending hidden audio element
- [ ] Provide an example of user's choice of TTS voice
- [x] Fn stop
- [x] Fn pause
- [x] Fn resume
- [x] Fn isSpeaking
- [x] Pitch option
- [x] Async