0.1.1 • Published 7 years ago

speech-js v0.1.1

Weekly downloads
18
License
MIT
Repository
github
Last release
7 years ago

speech-js

speech recognition and speech synthesis

DEMO

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)

PropertiesDefault valueTypeRange
text' 'String
voicesystem langString or Object
reate1Number0.1 - 10
volume1Number0 - 1
pitch1Number0 - 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)

PropertiesDefault valueTypeRange
langsystem langString
alternatives5Numberinfinity
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()