# tts-player

> a cross-platform tts(text to speach) player

Latest version **1.0.1** (published 2019-11-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install tts-player
pnpm add tts-player
yarn add tts-player
bun add tts-player
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-11-26 |
| First published | 2019-11-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ivan liu |
| Maintainers | ivan_liuqi |
| Keywords | tts, websocket |

## Links

- npm: https://www.npmjs.com/package/tts-player
- Repository: https://github.com/18566246732/tts-player
- Homepage: https://github.com/18566246732/tts-player#readme
- Issues: https://github.com/18566246732/tts-player/issues
- npm.io page: https://npm.io/package/tts-player

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-11-26
- 1.0.0 — 2019-11-26

## 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();
```

---
_Source: https://npm.io/package/tts-player · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
