Skip to main content

pyjsgf

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.

Metadata

Release files for pyjsgf 1.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyjsgf 1.9.0
File Size Uploaded Provenance Actions
pyjsgf-1.9.0.tar.gz 74.4 kB Without provenance Details for pyjsgf-1.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyjsgf 1.9.0
File Interpreter ABI Platform Actions
pyjsgf-1.9.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for pyjsgf-1.9.0-py2.py3-none-any.whl

Total release size: 158.9 kB

Release files / pyjsgf-1.9.0.tar.gz

Download URL pyjsgf-1.9.0.tar.gz
Size 74.4 kB
Tags Source
SHA-256 checksum
How to use checksums
650168e6cca10f8accd7e5d1148b366cb6871dff0147636f1b3e297716c99b23
BLAKE2b-256 checksum
How to use checksums
ca30e4c2761fc977997e33e7da245f7a19fb7610c069df09a4454e827b38da63
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / pyjsgf-1.9.0-py2.py3-none-any.whl

Download URL pyjsgf-1.9.0-py2.py3-none-any.whl
Size 84.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9248c1b55f6e7b8ae1e25ab6f6293e826c73ecb6aef4878f7a6d8e44dfa1cdec
BLAKE2b-256 checksum
How to use checksums
fcadaed332b97b5e2685a0b76c30d1a7de72b972d410272093c5970d8ac601c7
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for pyjsgf 1.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page