Skip to main content

JSpeech Grammar Format (JSGF) compiler, matcher and parser package for Python.

Project description

Build Status Docs Status

JSpeech Grammar Format (JSGF) compiler, matcher and parser package for Python.

JSGF is a format used to textually represent grammars for speech recognition engines. You can read the JSGF specification here.

pyjsgf can be used to construct JSGF rules and grammars, compile them into strings or files, and find grammar rules that match speech hypothesis strings. Matching speech strings to tags is also supported. There are also parsers for grammars, rules and rule expansions.

pyjsgf has been written and tested for Python 2.7 and Python 3.5.

The documentation for this project is on readthedocs.org.

Installation

To install pyjsgf, run the following:

$ pip install pyjsgf

If you are installing in order to develop pyjsgf, clone/download the repository, move to the root directory and run:

$ pip install -e .

Usage Example

The following is a usage example for how to create a JSGF grammar with one rule, compile it and find matching rules given the speech string “hello world”:

from jsgf import PublicRule, Literal, Grammar

# Create a public rule with the name 'hello' and a Literal expansion 'hello world'.
rule = PublicRule("hello", Literal("hello world"))

# Create a grammar and add the new rule to it.
grammar = Grammar()
grammar.add_rule(rule)

# Compile the grammar using compile()
# compile_to_file(file_path) may be used to write a compiled grammar to
# a file instead.
# Compilation is not required for finding matching rules.
print(grammar.compile())

# Find rules in the grammar that match 'hello world'.
matching = grammar.find_matching_rules("hello world")
print("Matching: %s" % matching[0])

Running the above code would output:

#JSGF V1.0;
grammar default;
public <hello> = hello world;

Matching: PublicRule(name='hello', expansion=Literal('hello world'))

The first line of the grammar can be changed using the jsgf_version, charset_name, and language_name members of the Grammar class.

There are some usage examples in pyjsgf/examples which may help you get started.

Multilingual support

Due to Python’s Unicode support, pyjsgf can be used with Unicode characters for grammar, import and rule names, as well as rule literals. If you need this, it is better to use Python 3 or above where all strings are Unicode strings by default.

If you must use Python 2.x, you’ll need to define Unicode strings as either u"text" or unicode(text, encoding), which is a little cumbersome. If you want to define Unicode strings in a source code file, you’ll need to define the source code file encoding.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyjsgf-1.9.0.tar.gz (74.4 kB view details)

Uploaded Source

Built Distribution

pyjsgf-1.9.0-py2.py3-none-any.whl (84.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyjsgf-1.9.0.tar.gz.

File metadata

  • Download URL: pyjsgf-1.9.0.tar.gz
  • Upload date:
  • Size: 74.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for pyjsgf-1.9.0.tar.gz
Algorithm Hash digest
SHA256 650168e6cca10f8accd7e5d1148b366cb6871dff0147636f1b3e297716c99b23
MD5 04c4b9d553c1c85329c00a2a512e1538
BLAKE2b-256 ca30e4c2761fc977997e33e7da245f7a19fb7610c069df09a4454e827b38da63

See more details on using hashes here.

File details

Details for the file pyjsgf-1.9.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pyjsgf-1.9.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 84.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for pyjsgf-1.9.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9248c1b55f6e7b8ae1e25ab6f6293e826c73ecb6aef4878f7a6d8e44dfa1cdec
MD5 f24ac2da95da41f6dc9fdb72e9307903
BLAKE2b-256 fcadaed332b97b5e2685a0b76c30d1a7de72b972d410272093c5970d8ac601c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page