Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Objective-C Library that provides tools for working with speech recognition. It provides data structures for pronunciation dictionaries, grammars, searches (Keyword Spotting, NGram, Grammar) and hypotheses. It also can parse and serialise JSGF grammars. Currently provides frameworks for iOS and OSX.

License

ynop/NTSpeechTools

Repository files navigation

NTSpeechTools

Carthage compatible GitHub license

NTSpeechTools is a library providing tools for working with speech recognition on iOS and OSX, written in Objective-C.

Features

  • Pronunciation Dictionary
  • Datastructures to dynamically work on grammars
  • Parse and serialize JSGF
  • Searches (A search is used to represent a method a engine uses to recognize speech e.g. Grammar, KWS, NGram)
  • Hypothesis

How to get started

Carthage

You can use carthage to install NTSpeechRecognition by adding to following to your Cartfile:

github "ynop/NTSpeechTools"

Manual

You also can add this project as subproject.

Documentation

API Reference

Checkout out API Reference.

Grammar Datastructure

This diagram shows the elements and their relations of the grammar data structure. (NTSpeechGrammar)

Usage

@import NTSpeechTools;
// or
#import <NTSpeechTools/NTSpeechTools.h>

Phonetic Dictionary

// Create a dictionary
NTPronunciationDictionary* dic = [NTPronunciationDictionary new];

// Add single word
[dic addWord:@"Flight" phones:@"F L AY T"];

// Add words from dictionary
[dic addWords:@{
    @"Flight" : @[ @"F L AY T", @"F L eY T" ],
    @"AC" : @[ @"EY S IY" ]
}];

//Get pronunciations for a word
NSArray* phoneList = [dic phonesForWord:@"flight"];

Grammar

The grammar we want to create:

#JSGF V1.0;

grammar politeness;

// Body
public <startPolite> = (please | kindly | could you | oh  mighty  computer) *;
<endPolite> = [ please | thanks | thank you ];
// CREATE ALTERNATE LIST
NTSpeechGrammarAlternative* startPoliteAlternative = [NTSpeechGrammarAlternative alternativeWithElements:@[
  @"please",
  @"kindly",
  [NTSpeechGrammarSequence sequenceWithTokens:@[ @"could", @"you" ]],
  [NTSpeechGrammarSequence sequenceWithTokens:@[ @"oh", @"mighty", @"computer" ]]
]];

// CREATE GROUP AND SET REPETITION
NTSpeechGrammarGroup* startPoliteGroup = [NTSpeechGrammarGroup groupWithRoot:startPoliteAlternative];
startPoliteGroup.repeatMode = REPEAT_ZERO_OR_MORE;

// CREATE RULE
NTSpeechGrammarRule* startPoliteRule = [NTSpeechGrammarRule publicRuleWithName:@"startPolite" root:startPoliteGroup];

// CREATE ALTERNATE LIST
NTSpeechGrammarAlternative* endPoliteAlternative = [NTSpeechGrammarAlternative alternativeWithElements:@[
  @"please",
  @"thanks",
  [NTSpeechGrammarSequence sequenceWithTokens:@[ @"thank", @"you" ]]
]];

// CREATE RULE WITH OPTIONAL GROUP
NTSpeechGrammarRule* endPoliteRule = [NTSpeechGrammarRule ruleWithName:@"endPolite" root:[NTSpeechGrammarGroup optionalGroupWithRoot:endPoliteAlternative]];

// CREATE GRAMMAR
NTSpeechGrammar* grammar = [NTSpeechGrammar grammarWithName:@"politeness"];
grammar.version = @"V1.0";

// ADD RULES
[grammar addRule:startPoliteRule];
[grammar addRule:endPoliteRule];

JSGF

// Parse from jsgf file
NTSpeechGrammar* grammar = [NTJsgfGrammar grammarFromFileAtPath:@"/path/to/grammar.jsgf"];

// Parse from string
NTSpeechGrammar* grammar = [NTJsgfGrammar grammarFromString:@"#JSGF V1.0; ........"];

// Serialize to a jsgf file
BOOL success = [NTJsgfGrammar writeGrammar:grammar toFileAtPath:@"/path/to/grammar.jsgf"];

// Serialize to string
NSString *serialized = [NTJsgfGrammar serializeGrammar:grammar];

Searches

// Keyword spotting
NTKeywordSpottingSearch *kws = [NTKeywordSpottingSearch searchWithName:@"kws" keyword:@"jarvis"];

// Grammar
NTSpeechGrammar *grammar = [NTJsgfGrammar grammarFromFileAtPath:@"/path/to/grammar.jsgf"];
NTGrammarSearch *grammarSearch = [NTGrammarSearch searchWithName:@"grammar" grammar:grammar];

// JSGF
NTJsgfFileSearch *jsgfSearch = [NTJsgfFileSearch searchWithName:@"jsgf" path:@"path/to/grammar.jsgf"];

// N-Gram
NTNGramFileSearch *ngramSearch = [NTNGramFileSearch searchWithName:@"ngram" path:@"path/to/ngram.lm"];

About

Objective-C Library that provides tools for working with speech recognition. It provides data structures for pronunciation dictionaries, grammars, searches (Keyword Spotting, NGram, Grammar) and hypotheses. It also can parse and serialise JSGF grammars. Currently provides frameworks for iOS and OSX.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published