npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jspeech

v0.1.1

Published

Create JSpeech Grammar Formats (JSGF).

Downloads

368

Readme

jspeech

Dependencies Status XO code style

Node.js module for creating JSpeech Grammar Formats, JSGF.

Note: jspeech is just a api for creating JSGF. The format specification can be read here: https://www.w3.org/TR/jsgf.

Usage

import jspeech from 'jspeech';

const grammar = jspeech('cockney');

grammar.rule('stairs', 'apples and pears');

grammar.stringify(); // #JSGF V1.0 utf-8 en; grammar cockney; <stairs> = apples and pears;

Creating Grammar

To create a speech grammar simply call the factory function from jspeech with the name of the grammar and any header options.

const grammar = jspeech('name', {
    version: 'V1.0',
    lang: 'en',
    encoding: 'utf-8',
});

Adding Rules

Add rules to the grammar object via the .rule() method. A rule must have a name and an valid JSGF rule token(s).

grammar.rule('hello', 'hello'); // <name> = hello'
grammar.rule('greeting', '(<hello> | hey | sup)'); // <greeting> = (<hello> | hey | sup);
grammar.rule('greet', '<greeting> buddy'); // <greet> = <greeting> buddy;

Public Rules

Only public rules are exported to a recogniser. To make a rule public use the .public API on the grammar object.

grammar.public.rule('friend', 'everyone'); // public <friend> = everyone;

Sequences

To ensure that a rule keeps a sequence of tokens together use the .word() method to wrap the tokens in quotes.

grammar.word('nyc', 'New York City'); // <nyc> = "New York City";

Alternatives, Weights and Groups

Alternatives allow variations of different rules and/or rule tokens. This allows for a more complex grammar format. Use the .alt() method to create different rule alternatives.

grammar.alt('cities', ['London', 'Sydney', 'Tokyo']); // <cities> = London | Sydney | Tokyo;
grammar.alt('colours', [
    ['red', 0.5],
    ['green', 0.3],
    ['blue', 0.8],
]); // <colours> = /0.5/ red | /0.3/ green | /0.8/ blue;

Alternatives can also accept options which allow token groups.

grammar.alt('answer', ['yes', 'no', 'maybe'], {
    group: true,    // creates group
    optional: true, // wrap in [] instead of ()
}); // <answer> = [yes | no | maybe];

Generating Format

Once a grammar has been created and all rules are defined. It can be used to generate the JSGF for use with a SpeechGrammarList.

import window from 'global/window';
import grammar from './grammar';

const SpeechGrammarList = window.SpeechGrammarList || window.webkitSpeechGrammarList;

const list = new SpeechGrammarList();
list.addFromString(grammar.stringify());

API

#jspeech(<name>, [header])

  • name String Grammar name.
  • header Object Grammar header information.

Returns a grammar object.

Grammar Object

grammar.rule(<name>, [token, [opts]])

grammar.public.rule(<name>, [token, [opts]])

  • name String Name of token.
  • token String|Array Token or array of alternative tokens.
  • opts Object Rule options.

Returns Void.

grammar.word(<name>, [word, [opts]])

grammar.public.word(<name>, [word, [opts]])

  • name String Name of word token.
  • word String Word token.
  • opts Object Rule options.

Returns Void.

grammar.alt(<name>, [alternatives, [opts]])

grammar.public.alt(<name>, [alternatives, [opts]])

  • name String Name of word token.
  • alternatives Array Array of alternative tokens.
  • opts Object Rule options.

Returns Void.

grammar.tokens()

Returns an Array of rule definitions.

grammar.stringify()

Returns a String of the generated JSGF.

License

MIT

Copyright (c) 2017 Christopher Turner