Git Product home page Git Product logo

speech-router's Introduction

Speech Router

Speech Router is a wrapper around Chrome's speech recognition APIs. It enables you to declare "routes" (similar to Backbone routes) which map speech to functionality within your application.

Demo here.

Usage

<html>
	<head>
		<script type="text/javascript" src="speech-router.js"></script>
		<script type="text/javascript">
			var router = new SpeechRouter({
				routes: {
					"go to youtube": "youtube",
					"say hello to :name": "sayHello",
					"search :engine for *query": "search"
				},
				
				youtube: function () {
					window.location.href = "http://google.com";
				},
				
				sayHello: function (name) {
					alert("Hi, " + (name || "there") + "!");
				},
				
				search: function (engine, query) {
					window.open("http://" + engine + ".com/search?q=" + query);
				}
			});
			
			router.start();
		</script>
	</head>
	<body></body>
</html>

API

new SpeechRouter(properties)

Constructor. All properties will be copied onto the object. properties should contain a routes hash that maps formats to functions:

new SpeechRouter({
	routes: {
		"search google for *query": function (query) {
			window.open("https://google.com/search?q=" + query);
		}
	}
});

The function can either be a string that maps to a function or an inline function. The format can contain parameters:

  • :param Matches any text not containing whitespace
  • *param Matches any text (with/without spaces)
  • (optional) Makes the selection optional (i.e., the route will fire the associated function regardless of whether or not the given text is found)

route(transcript, callback)

Associate the given callback function with the given format. This can be used to add routes on the fly. If the first argument is an object instead of a string, it is assumed that it is a hash of routes, similar what is expected in the constructor.

router.route("say hello to :name", function (name) {
	alert("Hi, " + name + "!");
});

trigger(transcript)

Manually invoke the function associated with a transcript. This function is also used internally to invoke functions associated with a speech recognition transcript.

router.trigger("say hello to Lukas");

start()

Starts speech recognition. This will bring up the default Chrome dialog to allow permission to access the user microphone. To prevent this dialog from occurring each time, use https instead of http.

router.start();

stop()

Stops speech recognition.

router.stop();

speech-router's People

Contributors

lukasolson avatar blittle avatar

Watchers

Justin Farrow avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.