Inline Grammars¶
An inline grammar is a grammar in which the grammar body is informed directly in the recognition request. In this case, ASR receives and compiles the grammar provided.
Fig. 12 Reference to inline grammar¶
Here are usage examples for different APIs:
REST API
POST /asr/rest/v3/recognize HTTP/1.1
Host: 127.0.0.1:8025
Content-Length: ...
Content-Type: multipart/form-data; boundary=BOUNDARY
--BOUNDARY
Content-Disposition: form-data; name="lm";
Content-Type: application/srgs
(corpo da gramática)
--BOUNDARY
Content-Disposition: form-data; name="audio";
Content-Type: audio/wav
(conteúdo do áudio)
--BOUNDARY--
Example with Rest API using Linux curl command. The grammar body must be in a file.
curl --form “lm=@/opt/grammar/pizza.gram;type=application/srgs”
--form “audio=@/opt/training/audio/pizza-veg-8k.wav;type=audio/wav”
http://127.0.0.1:8025/asr/rest/v3/recognize
WebSocket API
C->S: ASR 2.4 START_RECOGNITION
Content-Type: application/srgs
Content-Length: …
#ABNF 1.0 UTF-8;
language pt-BR;
mode voice;
root $root;
$root = sim | não;
MRCPv2 API
C->S: MRCP/2.0 ... RECOGNIZE 543260
Channel-Identifier:32AECB23433801@speechrecog
Content-Type:application/srgs
Content-ID: yes_no
Content-Length:...
#ABNF 1.0 UTF-8;
language pt-BR;
mode voice;
root $root;
$root = sim | não;
Creating LanguageModel object in JAVA for use with GRPC
public RecognitionConfig.LanguageModel createLanguageModelUsingLocalGrammarFile(String inlineGrammar) {
RecognitionConfig.LanguageModel lm = RecognitionConfig.LanguageModel.newBuilder()
.setId(Integer.toHexString(inlineGrammar.hashCode())).setContentType("application/srgs")
.setDefinition(inlineGrammar).build();
}