https://github.com/18566246732/tts-player
a cross-platform tts(text to speak) player
https://github.com/18566246732/tts-player
audio tts websocket
Last synced: 3 months ago
JSON representation
a cross-platform tts(text to speak) player
- Host: GitHub
- URL: https://github.com/18566246732/tts-player
- Owner: 18566246732
- Created: 2019-11-26T10:11:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-26T11:35:13.000Z (over 6 years ago)
- Last Synced: 2025-03-22T19:01:45.039Z (over 1 year ago)
- Topics: audio, tts, websocket
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# tts player
## description
a fast, simple, and cross-platform solution for play tts
## Installation
```bash
npm i tts-player
yarn add tts-player
```
## usage
- init tts, for ios compatibility, please call `tts.init()` on a user interaction callback like `onclick`, normally, the `ttsSampleRate` is 8000 or 16000
```js
import TTS from 'tts-player';
const tts = new TTS();
tts.init({
ttsSampleRate: 8000
});
```
- 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
```js
// the caching may take a while before it's ready to play
const ws = new WebSocket();
ws.onmessage = (data) => {
if (typeof data === 'string') {
const { ttsChunk, textId } = JSON.parse(data);
tts.add(ttsChunk, textId);
}
}
```
- play 1 sentence, the return value should be a duration if tts is ready
```js
const playTTSDuration = tts.play1Sentence(textId);
if (!playTTSDuration) throw new Error('tts is not ready !');
console.log(playTTSDuration); // 3.2
```
- stop play 1 sentence
```js
tts.stop();
```