1.4.2 • Published 2 years ago

@sunpodder/talker v1.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

talk.js

A Javascript Library with the Web Speech API.

Intro

With this library you can use text to speech and speech to text in a few lines of code. Written in pure Javascript, runs directly on the browser.

This project is open sourced. You can modify and share this code or do anything you want. Just give a little credit to me.

This project is under constant development. If you found a bug, please report it.

Contributions are always welcome.

Usage

Link to the library:

<script src="https://unpkg.com/@sunpodder/talker@1.4.2/dist/talk.js" ></script>

Or

Install from NPM:

npm install @sunpodder/talker

First check if browser supports Speech Synthesis.

if('speechSynthesis' in window){
  //talker code here
}else{
  //browser doesn't support these features
}

Create a new instance.

const talker = new Talker()

Now just pass a string inside the talk() method to talk.

talker.talk("hello world!")

Additional Settings

These are the default values. You can change the following values and experiment with them.

talker.volume = 1 //legal range 0-1
talker.rate = 1 //legal range 1-10
talker.pitch = 2 //legal range 1-2
talker.lang = 'en'

Grammars (optional)

Sets some words to be detected by the talker.

talker.grammar = {name: "hi", words: ["hi", "hello", "hey"]}

Though I don't think this is necessary for this simple words (hi, hello). Talker can automatically detect them.

If you have to detect some really complex words, you can set this grammar.

Speech to Text

Use the listen() method to listen to the user.

Pass a function to run when user has said something.

talker.listen(res => {
  alert("You said: " + res)
})

You can also pass 3 additional arguments.

Syntax is:

talker.listen(onResult, onStart, onNoMatch, onErr)

onResult: Calls when talker has recognized a word or phrase. onStart: Calls when recognition system has started. onNoDetection: Calls when recognition system couldn't recognize anything. onErr: Calls when an error occurred.

If you pass 3 arguments, the 3rd one will used as the onErr argument.

There is a html file with a demo code usage. Check it.

Live Demo here

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.0.0

3 years ago