Beispiel #1
0
        public RecognizedAudio GetAudioForWordRange(RecognizedWordUnit firstWord, RecognizedWordUnit lastWord)
        {
            Helpers.ThrowIfNull(firstWord, nameof(firstWord));
            Helpers.ThrowIfNull(lastWord, nameof(lastWord));

            return(Audio.GetRange(firstWord._audioPosition, lastWord._audioPosition + lastWord._audioDuration - firstWord._audioPosition));
        }
Beispiel #2
0
        private static bool ExecuteOnParse(Grammar grammar, RuleNode ruleRef, SemanticValue value, IList <RecognizedWordUnit> words, out object newValue)
        {
            ScriptRef[] scripts = grammar._scripts;
            bool        result  = false;

            newValue = null;
            foreach (ScriptRef scriptRef in scripts)
            {
                if (!(ruleRef._rule == scriptRef._rule) || scriptRef._method != RuleMethodScript.onParse)
                {
                    continue;
                }
                RecognizedWordUnit[] array = new RecognizedWordUnit[ruleRef._count];
                for (int j = 0; j < ruleRef._count; j++)
                {
                    array[j] = words[j];
                }
                object[] parameters = new object[2]
                {
                    value,
                    array
                };
                if (grammar._proxy != null)
                {
                    Exception exceptionThrown;
                    newValue = grammar._proxy.OnParse(scriptRef._rule, scriptRef._sMethod, parameters, out exceptionThrown);
                    if (exceptionThrown != null)
                    {
                        throw exceptionThrown;
                    }
                }
                else
                {
                    MethodInfo onParse;
                    Grammar    ruleInstance;
                    GetRuleInstance(grammar, scriptRef._rule, scriptRef._sMethod, out onParse, out ruleInstance);
                    newValue = onParse.Invoke(ruleInstance, parameters);
                }
                result = true;
            }
            return(result);
        }