tts player
description
a fast, simple, and cross-platform solution for play tts
Installation
npm i tts-playeryarn add tts-player
usage
- init tts, for ios compatibility, please call
tts.init()
on a user interaction callback likeonclick
, normally, thettsSampleRate
is 8000 or 16000
;const tts = ; tts;
- cache tts chunks, the ttsChunk must be pcm buffer which encoded with base64, normally, we get ttsChunk from other server, and in most cases, the ttsChunk is base64 encode for transportation comfortability
// the caching may take a while before it's ready to playconst ws = ;ws { if typeof data === 'string' const ttsChunk textId = JSON; tts; }
- play 1 sentence, the return value should be a duration if tts is ready
const playTTSDuration = tts;if !playTTSDuration throw 'tts is not ready !';console; // 3.2
- stop play 1 sentence
tts;