Tech Blog
  • HOME
  • Blog
  • Only select specific words! Rule grammar and 3 useful parameters

Only select specific words! Rule grammar and 3 useful parameters

Published: 2026.07.22 Last updated: 2026.08.03

Covered in tea


Hello. This is Chamamire.

In May 2026, three new request parameters were added to the AmiVoice API:
"confidenceLevel", "completeTimeout", and "wildcardModelPenalty".

These three parameters are particularly useful when using a rule grammar engine.
Please refer to the manual for information on how to use the parameters.

What Exactly Is Rule Grammar?

Even among users of the AmiVoice API, there may be some who are unfamiliar with rule grammar or engines for rule grammar.

This is a special engine available through the AmiVoice API Private, which allows you to configure it to recognize only expressions that follow a grammar (rules) set in advance by the user.

For example, imagine the way you would order at a restaurant.

"One salt ramen, two soy sauce ramen, one mixed fried rice, two dumplings, and three oolong teas. That's all, please."

In this utterance, the main part consists of an arbitrary number of repetitions of "<menu name> <quantity>". Furthermore, <menu name> can only refer to the names of menu items offered at that particular store, suggesting that the possible words to be spoken are limited.

In this way, when there are established rules for utterances (<menu name> <quantity>) and words to be used (individual words in <menu name>, numbers and numerals used in <quantity>), it is possible to create a rule grammar that specifies these rules in advance, thereby allowing the system to recognize only utterances that conform to those rules.

For example, if you create a rule grammar that does not include "pizza" in the menu name, the recognition result "one pizza" will not be produced. Also, utterances that are completely different from the rule, such as "meet at 9 tomorrow," will not be recognized.

For information on recognition using rule grammar, please refer to the manual (Rule Grammar | AmiVoice API Manual | AmiVoice Cloud Platform), as well as our technical blog where we provide detailed explanations. Please feel free to review these resources.

Confidence threshold: confidenceLevel

The recognition results returned by the AmiVoice API include information called "confidence". This is a numerical value that represents the degree to which the speech recognition engine considers the recognition result for that portion to be reliable.The value ranges from 0 to 1, and the closer it is to 1, the more reliable the recognition result is considered to be. The confidence is output for both word-level and speech segment-level results respectively.

"confidenceLevel" is a parameter that allows you to specify the minimum threshold for confidence level on each speech segment basis. When this parameter is used, recognition results for speech segments with confidence values lower than the specified value will be rejected. In other words, this enables the rejection of recognition results in which the speech recognition engine itself has low confidence. By default, it is set to 0.1, so only recognition results with significantly low confidence and questionable accuracy will be rejected.

This parameter itself can be applied even when using speech recognition engines other than the rule grammar engine.
For example, in the case of speech that is difficult to recognize, such as speech with a lot of noise or speech that is too quiet, the confidence value tends to be low, and the accuracy of the recognition result will not be very good. If "confidenceLevel" is used for speech recognition processing of such speech, the result will be rejected for speech segments in which the "confidence" is lower than the value specified by the user.

The rule grammar engine will also behave similarly if "confidenceLevel" is specified.
For example, let's try speech recognition using the rule grammar for recognizing the restaurant order utterances mentioned at the beginning. The rule is "<menu name> [to] <quantity>". <menu name> can be salt ramen, soy sauce ramen, mixed fried rice, dumplings, or oolong tea, <quantity> can be "one, two, ... nine" or "one, two, ... nine", and [to] can appear 0 or 1 time.

#JSGF V1.0 UTF-8;
grammar order;

public <order> = <item> [を] <count>;

public <item> = ( 醤油ラーメン\らーめん/しょうゆらーめん {shoyu}
                | 塩ラーメン\しおらーめん {sio}
                | 五目チャーハン\ごもくちゃーはん/ちゃーはん {chahan}
                | 餃子\ぎょうざ {gyoza}
                | ウーロン茶\うーろんちゃ {oolong}
                );

<count> = ( 一つ\ひとつ {1} | 二つ\ふたつ {2} | 三つ\みっつ {3} | 四つ\よっつ {4} | 五つ\いつつ {5}
          | 六つ\むっつ {6} | 七つ\ななつ {7} | 八つ\やっつ {8} | 九つ\ここのつ {9}
          | 一個\いっこ {1} | 二個\にこ {2}   | 三個\さんこ {3} | 四個\よんこ {4} | 五個\ごこ {5}
          | 六個\ろっこ {6} | 七個\ななこ {7} | 八個\はっこ {8} | 九個\きゅーこ {9}
          );

Now, let us try to recognize the utterance "行田お散歩(ぎょうだおさんぽ)".
By default, that is, with "confidenceLevel=0.1", the recognition result was "餃子を三個". Next, when the recognition was performed with "confidenceLevel=0.6" specified, it was rejected because the confidence level fell below the threshold.

On the other hand, when the same audio "行田お散歩" was recognized using the Conversation_General engine (-a-general), it was recognized as "行田お散歩", and it was not rejected even when the "confidenceLevel" was raised to 0.9.In other words, this recognition result of "行田お散歩" was one that the speech recognition engine had high confidence in.

In speech recognition engines that do not use rule grammars, such as the Conversation_General-purpose engine (engine that performs recognition by dictation), the most likely result is selected from many candidates for the input speech and output as the recognition result. For example, among the candidates for the utterance "行田お散歩", there might have included "餃子を三個", but since "行田お散歩" was judged to have a higher probability among those candidates and output as the recognition result, the reliability tends to be high.


On the other hand, with rule-based speech recognition, the recognition result is selected from a limited range of predetermined rules. Of course, if an utterance is determined not to fit these rules, no recognition result will be output. However, in the case of utterances that are somewhat similar to those that fit the rules, such as "行田お散歩", there is a possibility that the recognition result will be output with low confidence. In such cases, by specifying a threshold using "confidenceLevel," it becomes possible to reject recognition results that are likely to be incorrect.
However, sometimes the "confidence" score doesn't drop that low even if the recognition result is incorrect, and sometimes the "confidence" score is low even if the recognition result is correct. It's a good idea to adjust the balance while observing the results, and if necessary, revise the rules, such as adjusting the reading.

As a side note, Gyoda City in Saitama Prefecture, not known for its gyoza (dumplings), boasts many historically romantic spots such as the Ancient Lotus Village, the Saitama Kofun Group (ancient burial mounds), and the ruins of Oshi Castle, famous for Ishida Mitsunari's water siege. How about visiting during a pleasant season?

Wildcard Penalty: wildcardModelPenalty

These parameters are only valid for engines designed for rule grammar.

Within a rule grammar, there is a special rule name called "<GARBAGE>". This is a special rule that matches any utterance, and the portions of the utterance determined to be <GARBAGE> are not output as recognition results.
For example, suppose a rule is created as "<GARBAGE> <num> <GARBAGE>", where <num> contains one digit from 1 to 9. When this is used to recognize the utterance "それは2です", "それは" and "です" are each recognized as <GARBAGE>, and only "2" is output as the recognition result.

"wildcardModelPenalty" is a parameter that specifies the degree to which an utterance is likely to be recognized as <GARBAGE> when performing speech recognition using a rule grammar with this <GARBAGE>. The specifiable range is approximately 2.0 to 6.0, where smaller values make it more likely to be recognized as <GARBAGE>, and larger values make it more likely to be recognized as something other than <GARBAGE>.

As an example, prepare a rule grammar that recognizes the numbers 1 through 9 and the three alphabetic characters S, M, and L. As shown below, alphanumeric characters may continue for any number of digits, and the end shall have <GARBAGE> zero or more times (<GARBAGE> may or may not be present).

#JSGF V1.0 UTF-8;
grammar Alphanumeric;
public <alphanumeric> = <alnum>+ <GARBAGE>*;
<alnum> = 1\いち {1} | 2\に/にー {2} | 3\さん {3} | 4\よん/し/しー {4} 
        | 5\ご {5} | 6\ろく {6} | 7\なな/しち {7} | 8\はち {8} 
        | 9\きゅー/く/くー {9} | 0\ぜろ/れー/まる {0} 
        | S\えす {s} | M\えむ {m} | L\える {l};

Using this, we will attempt to recognize the utterance "1234です".
First, when recognition was performed with "wildcardModelPenalty=2.0", the recognition result was "1234". In other words, "です" was recognized as <GARBAGE>.
Next, by increasing the number to "wildcardModelPenalty=4.0," that is, by configuring the setting to make it easier to recognize items as something other than <GARBAGE>, the recognition result became "1234S". In this case, "です" was recognized as "S(えす)" instead of <GARBAGE>.

<GARBAGE> is a convenient rule for processing unnecessary utterances that cannot be fully anticipated in advance as speech patterns, like sentence endings, and are not needed in the recognition results. However, because it is an "anything goes" rule, there is a possibility that parts that should have been output as recognition results may be processed as <GARBAGE>, and conversely, parts that should have been processed as <GARBAGE> may be output as something else. By using "wildcardModelPenalty," it becomes possible to adjust this balance.

Confirmation waiting timeout: completeTimeout

This parameter is also only valid for engines designed for rule grammar.

This feature allows you to specify the length of time (in milliseconds) to wait for the next utterance input if, while speech recognition processing is underway for a given speech segment, the recognition results obtained so far already meet the conditions for the recognition result expected from the rule grammar.
In other words, if a recognition result matching the rule grammar has already been obtained after processing part of a speech segment, and the next utterance does not begin within a certain time (completeTimeout), it becomes possible to stop processing that speech segment at that point and finalize the recognition result.

As an example, let's prepare a rule grammar for recognizing "はい/いいえ (yes/no)". As shown below, the utterance to be recognized is either "はい (yes)" or "いいえ(no)", and it is acceptable for other utterances to follow "はい/いいえ (yes/no)" (<GARBAGE>*).

#JSGF V1.0 UTF-8;
grammar Yesno;
public <yesno> = <yesorno> <GARBAGE>*;
<yesorno> = はい\はい {yes} | いいえ\いいえ {no};

Using this, we will attempt to recognize speech such as "はい、ええ、まあ、そうです、はい……" where the speaker continues to ramble on after saying "はい", by sending the audio incrementally through the WebSocket interface. This is a speech recognition system that is expected to classify the rambling portion as <GARBAGE>, with the recognition result being only "はい".
In this audio, the speech segment detection process detected a speech segment lasting approximately 6.2 seconds.
Additionally, we set "resultUpdateInterval=500" (sending intermediate recognition results once every 0.5 seconds) to allow for detailed monitoring of the recognition process.

First, when we attempted recognition with "completeTimeout=10000" (10 seconds), a total of 12 intermediate result U events were sent before the recognition result was confirmed as "はい" and the A event was transmitted. Of these, all except the first one had intermediate recognition results of "はい". Additionally, it took approximately 6 seconds from when the C event indicating the start of speech recognition was sent until the A event was sent. Furthermore, the A event was sent after the E event, which is the notification that the end of the utterance section was detected.

Next, when recognition was performed with "completeTimeout=200" (0.2 seconds), the intermediate result U event was sent only twice before the recognition result was confirmed as "はい" and the A event was sent. Among these, in the second U event, the interim recognition result was "はい". Additionally, the time elapsed from when the C event indicating the start of speech recognition was sent until the A event was sent was approximately 1.5 seconds, and the A event was sent before the E event.
In other words, during the processing of this speech segment, a recognition result matching the rule grammar, "はい" was obtained. As a result, a check was made to determine if a timeout would occur if no further utterance was made for 0.2 seconds. Since the timeout was triggered, the recognition result for this speech segment was finalized before the end of the speech segment was detected.

By setting a short "completeTimeout" in this way, even if utterances continue within the same utterance interval, if a recognition result that matches the rule is obtained, the recognition result can be determined quickly.

Let's try another pattern. This time, the rule is to recognize numbers with two or more digits. There is no upper limit to the number of digits, as long as it is two or more.

#JSGF V1.0 UTF-8;
grammar Numbers;
public <number> = <num> <num>+;
<num> = 1\いち {1} | 2\に/にー {2} | 3\さん {3} | 4\よん/し/しー {4} 
      | 5\ご {5} | 6\ろく {6} | 7\なな/しち {7} | 8\はち {8} 
      | 9\きゅー/く/くー {9} | 0\ぜろ/れー/まる {0};

Using this, we will attempt to recognize speech that reads out numbers in short segments as "1, 2, 3, 4, 5, 6, 7, 8, 9".

First, when recognition was performed with "completeTimeout=10000" (10 seconds), the recognition result was "123456789". In other words, recognition was performed up to the end of the utterance section.

Next, when recognition was performed with "completeTimeout=200" (0.2 seconds), the recognition result became "12". This means that when the initial utterance "1, 2" was recognized and the recognition result "12" was obtained, it matched the condition for the expected recognition result by the rule grammar (a number with two or more digits), and since there was no input even after waiting the specified 0.2 seconds for the next utterance input, the recognition result for that speech segment was confirmed at that point.

In this way, using "completeTimeout" makes it possible to quickly determine and obtain recognition results when short, single-word utterances like "はい/いいえ" are expected. Also, even in cases where there are certain rules (e.g., a sequence of numbers) but the rules have variability (e.g., multiple different numbers of digits), such as with phone numbers, it is possible to obtain a result without processing the entire utterance interval by expecting a pause after the utterance is finished and determining the result if there is no utterance for a certain period of time.

Make Rule Grammar More Useful by Utilizing Parameters

Speech recognition using rule grammar can achieve higher accuracy in certain situations. By using it in conjunction with the parameters introduced here, you should be able to use it even more effectively, so if there are any parameters that you think might be suitable for your use, please try them out.

Person who wrote this article

  • Covered in tea

    A person drinking tea while contemplating the potential of using voice for communication even when their hands are full.

     

AmiVoice "Rule grammar" related articles

Use API for Free