# speech-js

> lib for recognition and synthesis of speech

Latest version **0.1.1** (published 2017-08-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install speech-js
pnpm add speech-js
yarn add speech-js
bun add speech-js
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-08-17 |
| First published | 2017-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.0.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Igor Bezsmertnyi bezsmertnyi.igo@gmail.com |
| Maintainers | mr-igor |
| Keywords | speech, speech js, speech javascript, recognition, recognition js, recognition javascript, synthesis, synthesis js, synthesis javascript, speech recognition, speech recognition js, speech recognition javascript, speech synthesis, speech synthesis js, speech synthesis javascript |

## Links

- npm: https://www.npmjs.com/package/speech-js
- Repository: https://github.com/igorbezsmertnyi/speech
- Homepage: https://github.com/igorbezsmertnyi/speech#readme
- Issues: https://github.com/igorbezsmertnyi/speech/issues
- npm.io page: https://npm.io/package/speech-js

## Dependencies (2)

- [babel-cli](https://npm.io/package/babel-cli.md) ^6.24.1
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.24.1

## Recent versions

- 0.1.1 (latest) — 2017-08-17
- 0.1.0 — 2017-08-14
- 0.0.9 — 2017-08-13
- 0.0.8 — 2017-08-12
- 0.0.7 — 2017-08-12
- 0.0.6 — 2017-08-12
- 0.0.5 — 2017-08-12
- 0.0.4 — 2017-08-08
- 0.0.3 — 2017-08-07
- 0.0.2 — 2017-08-07
- 0.0.1 — 2017-08-07

## README

# speech-js
speech recognition and speech synthesis

[DEMO](https://igorbezsmertnyi.github.io/speech-demo/)

* [Instalation](#instalation)
* [Quick start](#quick-start)
* [Synthesis](#synthesis)
  * [voice](#voice)
  * [synthesis methods](#synthesis-methods)
* [Recognition](#recognition)
  * [grammar](#grammar)
  * [recognition methods](#recognition-methods)

# Instalation
`npm install speech-js --save` or `yarn add speech-js`

# Quick start
```
import speech from 'speech-js'

speech.synthesis('hello world', 'en-US') // speech synthesis module

const recognition = speech.recognition('en-US') // speech recognition module
recognition.start()
recognition.onresult = e => {
  let result = e.results[0][0].transcript
  speech.synthesis(result, 'en-US')
}
```

# Synthesis

`speech.synthesis(text, voice, rate, volume, pitch)`

| Properties | Default value | Type             | Range      |
| ---------- | ------------- | ---------------- | ---------- |
| text       | ' '           | String           |            |
| voice      | system lang   | String or Object |            |
| reate      | 1             | Number           | 0.1 - 10   |
| volume     | 1             | Number           | 0 - 1      |
| pitch      | 1             | Number           | 0 - 2      |

### voice
Voice properties can by `String` or `Object`

If you use `String` properties for `voice`, speech set lang properties. For example:
```
speech.synthesis('Hello World', 'en-US')
```

Or if you want use the other voices on your computer, code will be looks like this:

```
speechSynthesis.onvoiceschanged = () => {
  const voices = window.speechSynthesis.getVoices()
  speech.synthesis('hello world', voices[0])
}
```
where `voices` is an array with voices installed on your computer

### synthesis methods
`speechSynthesis.cancel()`

`speechSynthesis.pause()`

`speechSynthesis.resume()`

# Recognition

`speech.recognition(lang, alternatives, grammar)`

| Properties    | Default value | Type             | Range      |
| ------------- | ------------- | ---------------- | ---------- |
| lang          | system lang   | String           |            |
| alternatives  | 5             | Number           | infinity   |
| grammar       | ' '           | String           |            |

### grammar
The grammars property of the SpeechRecognition interface returns and sets a collection of SpeechGrammar objects that represent the grammars that will be understood by the current SpeechRecognition.

Example:
```
const grammar = #JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;
```

### recognition methods

`speech.recognition().start()`

`speech.recognition().stop()`

`speech.recognition().abort()`

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