32 std::cout <<
"Start building offline grammar for recognition ..." << std::endl;
33 std::cout <<
"Your grammar file is read from: " << grammar_file.c_str() << std::endl;
34 std::cout <<
"Your asr grammar file will save at: " << grammar_build_path.c_str() << std::endl;
38 std::ifstream infile(grammar_file.c_str());
41 infile.seekg(0, std::ios::end);
42 grm_cnt_len = infile.tellg();
43 infile.seekg(0, std::ios::beg);
44 grm_content =
new char[grm_cnt_len];
45 infile.read(grm_content, grm_cnt_len);
50 std::cout <<
"Fail to open expected Json file" << grammar_file << endl;
55 string tmp = string(
"engine_type = local, asr_res_path = " + asr_res_path +
", sample_rate = " +
56 to_string(
SAMPLE_RATE_16K) +
", grm_build_path = " + grammar_build_path +
", ");
57 const char* grm_build_params = tmp.c_str();
58 std::cout << grm_build_params << std::endl;
79 std::cout <<
"Building grammar failed!" << std::endl;
91 string filepath = grammar_build_path +
"/info.txt";
93 std::cout <<
"Build grammar finished!" << std::endl;
100 if (NULL != grm_data)
108 std::cout <<
"Build grammar success! Grammar ID: " << info << std::endl;
109 if (NULL != grm_data)
116 std::cout <<
"Build grammar failed! Error code:" << ecode << std::endl;
125 std::ofstream outfile(file_path);
127 if (outfile.is_open())
131 outfile << info->
errcode <<
'\n';
137 std::cout <<
"Fail to open expected Json file" << file_path << std::endl;
std::string grammar_build_path
static const int SAMPLE_RATE_16K
int MSPAPI QISRBuildGrammar(const char *grammarType, const char *grammarContent, unsigned int grammarLength, const char *params, GrammarCallBack callback, void *userData)
Mobile Speech Platform Common Interface Header File.
iFLY Speech Recognizer Header File
char grammar_id[MAX_GRAMMARID_LEN]
static int buildGrammarCallback(int ecode, const char *info, void *udata)
static const int BUILD_FINISH
void buildGrammar(UserData *udata, const string base_path, const string grammar_build_path, const string asr_res_path, const string grammar_file)
static int writeIntoFile(const string file_path, UserData *info)