{"id":15383362,"url":"https://github.com/tur-nr/node-jspeech","last_synced_at":"2025-06-28T01:06:11.186Z","repository":{"id":57286144,"uuid":"84795558","full_name":"tur-nr/node-jspeech","owner":"tur-nr","description":"Create JSpeech Grammar Formats (JSGF).","archived":false,"fork":false,"pushed_at":"2017-03-13T07:45:28.000Z","size":50,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T19:49:07.504Z","etag":null,"topics":["grammar","javascript","jsgf","nodejs","speech"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tur-nr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-13T07:16:21.000Z","updated_at":"2023-07-18T14:43:10.000Z","dependencies_parsed_at":"2022-09-10T02:00:19.864Z","dependency_job_id":null,"html_url":"https://github.com/tur-nr/node-jspeech","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tur-nr/node-jspeech","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tur-nr%2Fnode-jspeech","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tur-nr%2Fnode-jspeech/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tur-nr%2Fnode-jspeech/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tur-nr%2Fnode-jspeech/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tur-nr","download_url":"https://codeload.github.com/tur-nr/node-jspeech/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tur-nr%2Fnode-jspeech/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262357554,"owners_count":23298463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grammar","javascript","jsgf","nodejs","speech"],"created_at":"2024-10-01T14:37:08.653Z","updated_at":"2025-06-28T01:06:11.140Z","avatar_url":"https://github.com/tur-nr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jspeech\n\n![Dependencies Status](https://david-dm.org/tur-nr/node-jspeech.svg)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n\n[Node.js](https://nodejs.org) module for creating [JSpeech Grammar Formats, _JSGF_](https://www.w3.org/TR/jsgf).\n\n_Note_: `jspeech` is just a api for creating JSGF. The format specification can be read here: [https://www.w3.org/TR/jsgf](https://www.w3.org/TR/jsgf).\n\n## Usage\n\n```javascript\nimport jspeech from 'jspeech';\n\nconst grammar = jspeech('cockney');\n\ngrammar.rule('stairs', 'apples and pears');\n\ngrammar.stringify(); // #JSGF V1.0 utf-8 en; grammar cockney; \u003cstairs\u003e = apples and pears;\n```\n\n### Creating Grammar\n\nTo create a speech grammar simply call the factory function from `jspeech` with the name of the grammar and any header options.\n\n```javascript\nconst grammar = jspeech('name', {\n    version: 'V1.0',\n    lang: 'en',\n    encoding: 'utf-8',\n});\n```\n\n### Adding Rules\n\nAdd rules to the grammar object via the `.rule()` method. A rule must have a name and an valid JSGF rule token(s).\n\n```javascript\ngrammar.rule('hello', 'hello'); // \u003cname\u003e = hello'\ngrammar.rule('greeting', '(\u003chello\u003e | hey | sup)'); // \u003cgreeting\u003e = (\u003chello\u003e | hey | sup);\ngrammar.rule('greet', '\u003cgreeting\u003e buddy'); // \u003cgreet\u003e = \u003cgreeting\u003e buddy;\n```\n\n#### Public Rules\n\nOnly public rules are exported to a recogniser. To make a rule public use the `.public` API on the grammar object.\n\n```javascript\ngrammar.public.rule('friend', 'everyone'); // public \u003cfriend\u003e = everyone;\n```\n\n#### Sequences\n\nTo ensure that a rule keeps a sequence of tokens together use the `.word()` method to wrap the tokens in quotes.\n\n```javascript\ngrammar.word('nyc', 'New York City'); // \u003cnyc\u003e = \"New York City\";\n```\n\n#### Alternatives, Weights and Groups\n\nAlternatives 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.\n\n```javascript\ngrammar.alt('cities', ['London', 'Sydney', 'Tokyo']); // \u003ccities\u003e = London | Sydney | Tokyo;\ngrammar.alt('colours', [\n    ['red', 0.5],\n    ['green', 0.3],\n    ['blue', 0.8],\n]); // \u003ccolours\u003e = /0.5/ red | /0.3/ green | /0.8/ blue;\n```\n\nAlternatives can also accept options which allow token groups.\n\n```javascript\ngrammar.alt('answer', ['yes', 'no', 'maybe'], {\n    group: true,    // creates group\n    optional: true, // wrap in [] instead of ()\n}); // \u003canswer\u003e = [yes | no | maybe];\n```\n\n### Generating Format\n\nOnce a grammar has been created and all rules are defined. It can be used to generate the JSGF for use with a [SpeechGrammarList](https://developer.mozilla.org/en-US/docs/Web/API/SpeechGrammarList).\n\n```javascript\nimport window from 'global/window';\nimport grammar from './grammar';\n\nconst SpeechGrammarList = window.SpeechGrammarList || window.webkitSpeechGrammarList;\n\nconst list = new SpeechGrammarList();\nlist.addFromString(grammar.stringify());\n```\n\n## API\n\n#### `#jspeech(\u003cname\u003e, [header])`\n\n- `name` _String_ Grammar name.\n- `header` _Object_ Grammar header information.\n\n_Returns a grammar object._\n\n### Grammar Object\n\n#### `grammar.rule(\u003cname\u003e, [token, [opts]])`\n#### `grammar.public.rule(\u003cname\u003e, [token, [opts]])`\n\n- `name` _String_ Name of token.\n- `token` _String|Array_ Token or array of alternative tokens.\n- `opts` _Object_ Rule options.\n\n_Returns Void_.\n\n#### `grammar.word(\u003cname\u003e, [word, [opts]])`\n#### `grammar.public.word(\u003cname\u003e, [word, [opts]])`\n\n- `name` _String_ Name of word token.\n- `word` _String_ Word token.\n- `opts` _Object_ Rule options.\n\n_Returns Void_.\n\n#### `grammar.alt(\u003cname\u003e, [alternatives, [opts]])`\n#### `grammar.public.alt(\u003cname\u003e, [alternatives, [opts]])`\n\n- `name` _String_ Name of word token.\n- `alternatives` _Array_ Array of alternative tokens.\n- `opts` _Object_ Rule options.\n\n_Returns Void_.\n\n#### `grammar.tokens()`\n\n_Returns an Array of rule definitions._\n\n#### `grammar.stringify()`\n\n_Returns a String of the generated JSGF._\n\n## License\n\n[MIT](LICENSE)\n\nCopyright (c) 2017 [Christopher Turner](https://github.com/tur-nr)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftur-nr%2Fnode-jspeech","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftur-nr%2Fnode-jspeech","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftur-nr%2Fnode-jspeech/lists"}