Local Grammars

A local grammar is a grammar deposited in the directory of the ASR server itself. If the application uses multiple ASR servers, the grammar must be on all of them. The local grammar is used via the URI: file://<caminho da gramática>

../../_images/local_grammar.png

Fig. 9 Reference to local grammar

Here are usage examples for different APIs:

REST API

POST /asr/rest/V3/recognize?lm=file:///opt/grammar/pizza.gram HTTP/1.1
Host: 127.0.0.1:8025
Accept: */*
Content-Type: audio/wav
Content-Length: ...


<conteúdo binário do áudio>

WebSocket API

C->S: ASR 2.4 START_RECOGNITION
  Content-Type: text/uri-list
  Content-Length: …

  file:///opt/grammar/pizza.gram

MRCPv2 API

C->S: MRCP/2.0 ... RECOGNIZE 543260
  Channel-Identifier:32AECB23433801@speechrecog
  Content-Type:text/uri-list
  Content-Length:...

  file:///opt/grammar/pizza.gram

Creating LanguageModel object in JAVA for use with GRPC API

    public RecognitionConfig.LanguageModel createLanguageModelUsingLocalGrammarFile(Path fileUri) {
String lmDefinition = new String(Files.readAllBytes(fileUri));
RecognitionConfig.LanguageModel lm = RecognitionConfig.LanguageModel.newBuilder()
        .setId(Integer.toHexString(fileUri.hashCode())).setContentType("application/srgs")
        .setDefinition(lmDefinition).build();
    }