1 /*---------------------------------------------------------------------------*
2 * c47mulsp.c *
3 * *
4 * Copyright 2007, 2008 Nuance Communciations, Inc. *
5 * *
6 * Licensed under the Apache License, Version 2.0 (the 'License'); *
7 * you may not use this file except in compliance with the License. *
8 * *
9 * You may obtain a copy of the License at *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, software *
13 * distributed under the License is distributed on an 'AS IS' BASIS, *
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 * See the License for the specific language governing permissions and *
16 * limitations under the License. *
17 * *
18 *---------------------------------------------------------------------------*/
19
20 #ifndef _RTT
21 #include "pstdio.h"
22 #endif
23 #include "passert.h"
24
25 #include "c42mul.h"
26 #include "portable.h"
27 #include "srec_context.h"
28 #include "srec.h"
29
add_acoustic_model_for_recognition(multi_srec * recm,const SWIModel * model)30 int add_acoustic_model_for_recognition(multi_srec* recm, const SWIModel* model)
31 {
32 if (recm->num_swimodels >= MAX_ACOUSTIC_MODELS)
33 {
34 log_report("Error: recognizer can't hold any more acoustic models\n");
35 return 0;
36 }
37 if (recm->num_activated_recs >= recm->num_allocated_recs)
38 {
39 log_report("Error: too few recognizers allocated\n");
40 return 0;
41 }
42
43 if (recm->rec[0].num_model_slots_allocated < model->num_hmmstates)
44 {
45 PLogError("recognizer max_model_states %d, acoustic model num states %d, set CREC.Recognizer.max_model_states higher\n",
46 recm->rec[0].num_model_slots_allocated,
47 model->num_hmmstates);
48 return 0;
49 }
50
51 recm->swimodel[ recm->num_swimodels] = model;
52 recm->num_swimodels++;
53
54 recm->num_activated_recs++;
55 return 1;
56 }
57
clear_acoustic_models_for_recognition(multi_srec * recm)58 int clear_acoustic_models_for_recognition(multi_srec* recm)
59 {
60 recm->num_swimodels = 0;
61 recm->num_activated_recs = 0;
62 return 0;
63 }
64
begin_recognition(multi_srec * recm,int begin_syn_node)65 void begin_recognition(multi_srec *recm, int begin_syn_node)
66 {
67 int i = 0;
68 #if DO_ALLOW_MULTIPLE_MODELS
69 ASSERT(recm->num_activated_recs == recm->num_swimodels);
70 for (i = 0; i < recm->num_activated_recs; i++)
71 #endif
72 srec_begin(&recm->rec[i], begin_syn_node);
73 for (i = 0;i < recm->max_fsm_nodes;i++)
74 recm->best_token_for_node[i] = MAXftokenID;
75 recm->eos_status = VALID_SPEECH_CONTINUING;
76 }
77
end_recognition(multi_srec * recm)78 void end_recognition(multi_srec *recm)
79 /*
80 ** To free space allocated for recognizer variables
81 */
82 {
83 int i = 0;
84 #if DO_ALLOW_MULTIPLE_MODELS
85 for (i = 0; i < recm->num_activated_recs; i++)
86 #endif
87 srec_no_more_frames(&recm->rec[i]);
88 /* srec_get_result(rec); */
89 }
90
activate_grammar_for_recognition(multi_srec * recm,srec_context * grammar,const char * rule)91 int activate_grammar_for_recognition(multi_srec* recm, srec_context* grammar, const char* rule)
92 {
93 srec_context* context = grammar;
94
95 context->max_searchable_nodes = recm->max_fsm_nodes;
96 context->max_searchable_arcs = recm->max_fsm_arcs;
97
98 if (context->max_searchable_nodes < context->num_nodes || context->max_searchable_arcs < context->num_arcs)
99 {
100 PLogError(L("Error: context switch failed due to search limitations [arcs max=%d, actual=%d], [nodes max=%d, actual=%d]\n"),
101 context->max_searchable_arcs, context->num_arcs,
102 context->max_searchable_nodes, context->num_nodes);
103 return 1;
104 }
105 else
106 {
107 int i, rc = 0;
108 for (i = 0; i < recm->num_allocated_recs; i++)
109 recm->rec[i].context = context;
110 rc = FST_PrepareContext(context);
111 if (rc)
112 return rc;
113 else
114 return 0;
115 }
116 }
117
clear_grammars_for_recognition(multi_srec * recm)118 int clear_grammars_for_recognition(multi_srec* recm)
119 {
120 int i;
121 for (i = 0; i < recm->num_allocated_recs; i++)
122 {
123 recm->rec[i].context = NULL;
124 }
125 return 0;
126 }
127
128
129
130
131
132
133
134
135