bool DSMFactory::loadPromptSets(AmConfigReader& cfg) { string prompt_sets_path = cfg.getParameter("prompts_sets_path"); vector<string> prompt_sets_names = explode(cfg.getParameter("load_prompts_sets"), ","); for (vector<string>::iterator it= prompt_sets_names.begin(); it != prompt_sets_names.end(); it++) { string fname = prompt_sets_path.empty() ? "": prompt_sets_path + "/"; fname += *it; DBG("loading prompts for '%s' (file '%s')\n", it->c_str(), fname.c_str()); std::ifstream ifs(fname.c_str()); string s; if (!ifs.good()) { WARN("prompts set file '%s' could not be read\n", fname.c_str()); } AmPromptCollection* pc = new AmPromptCollection(); while (ifs.good() && !ifs.eof()) { getline(ifs, s); if (s.length() && s.find_first_not_of(" \t")!= string::npos && s[s.find_first_not_of(" \t")] != '#') { vector<string> p=explode(s, "="); if (p.size()==2) { pc->setPrompt(p[0], p[1], MOD_NAME); DBG("set '%s' added prompt '%s' as '%s'\n", it->c_str(), p[0].c_str(), p[1].c_str()); } } } prompt_sets[*it] = pc; } return true; }
int DSMFactory::onLoad() { if (loaded) return 0; loaded = true; AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) return -1; // get application specific global parameters configureModule(cfg); vector<string> prompts_files = explode(cfg.getParameter("load_prompts"), ","); for (vector<string>::iterator it= prompts_files.begin(); it != prompts_files.end(); it++) { DBG("loading prompts from '%s'\n", it->c_str()); std::ifstream ifs(it->c_str()); string s; while (ifs.good() && !ifs.eof()) { getline(ifs, s); if (s.length() && s.find_first_not_of(" \t")!= string::npos && s[s.find_first_not_of(" \t")] != '#') { vector<string> p=explode(s, "="); if (p.size()==2) { prompts.setPrompt(p[0], p[1], MOD_NAME); DBG("added prompt '%s' as '%s'\n", p[0].c_str(), p[1].c_str()); } } } } string prompt_sets_path = cfg.getParameter("prompts_sets_path"); vector<string> prompt_sets_names = explode(cfg.getParameter("load_prompts_sets"), ","); for (vector<string>::iterator it= prompt_sets_names.begin(); it != prompt_sets_names.end(); it++) { string fname = prompt_sets_path.empty() ? "": prompt_sets_path + "/"; fname += *it; DBG("loading prompts for '%s' (file '%s')\n", it->c_str(), fname.c_str()); std::ifstream ifs(fname.c_str()); string s; if (!ifs.good()) { WARN("prompts set file '%s' could not be read\n", fname.c_str()); } AmPromptCollection* pc = new AmPromptCollection(); while (ifs.good() && !ifs.eof()) { getline(ifs, s); if (s.length() && s.find_first_not_of(" \t")!= string::npos && s[s.find_first_not_of(" \t")] != '#') { vector<string> p=explode(s, "="); if (p.size()==2) { pc->setPrompt(p[0], p[1], MOD_NAME); DBG("set '%s' added prompt '%s' as '%s'\n", it->c_str(), p[0].c_str(), p[1].c_str()); } } } prompt_sets[*it] = pc; } string DiagPath = cfg.getParameter("diag_path"); if (DiagPath.length() && DiagPath[DiagPath.length()-1] != '/') DiagPath += '/'; string ModPath = cfg.getParameter("mod_path"); string preload_mods = cfg.getParameter("preload_mods"); vector<string> preload_names = explode(preload_mods, ","); if (preload_names.size()) { DSMChartReader reader; for (vector<string>::iterator it= preload_names.begin(); it != preload_names.end(); it++) { DBG("preloading '%s'...\n", it->c_str()); if (!reader.importModule("import("+*it+")", ModPath)) { ERROR("importing module '%s' for preload\n", it->c_str()); return -1; } DSMModule* last_loaded = reader.mods.back(); if (last_loaded) { if (last_loaded->preload()) { DBG("Error while preloading '%s'\n", it->c_str()); return -1; } } } } // TODO: pass preloaded mods to chart reader string LoadDiags = cfg.getParameter("load_diags"); vector<string> diags_names = explode(LoadDiags, ","); for (vector<string>::iterator it= diags_names.begin(); it != diags_names.end(); it++) { if (!diags.loadFile(DiagPath+*it+".dsm", *it, ModPath)) { ERROR("loading %s from %s\n", it->c_str(), (DiagPath+*it+".dsm").c_str()); return -1; } } InboundStartDiag = cfg.getParameter("inbound_start_diag"); if (InboundStartDiag.empty()) { INFO("no 'inbound_start_diag' set in config. inbound calls disabled.\n"); } OutboundStartDiag = cfg.getParameter("outbound_start_diag"); if (OutboundStartDiag.empty()) { INFO("no 'outbound_start_diag' set in config. outbound calls disabled.\n"); } for (std::map<string,string>::const_iterator it = cfg.begin(); it != cfg.end(); it++) config[it->first] = it->second; RunInviteEvent = cfg.getParameter("run_invite_event")=="yes"; return 0; }
AmPromptCollection* VoiceboxFactory::loadPrompts(string prompt_base_path, string domain, string language, bool load_digits) { AmPromptCollection* pc = new AmPromptCollection(); string prompt_path = prompt_base_path + "/" + domain + "/" + language + "/"; #define ADD_DEF_PROMPT(str) \ if (pc->setPrompt(str, prompt_path + str + ".wav", APP_NAME) < 0) { \ delete pc; \ return NULL; \ } // Parts for the welcome text ADD_DEF_PROMPT("pin_prompt"); ADD_DEF_PROMPT("you_have"); ADD_DEF_PROMPT("new_msgs"); ADD_DEF_PROMPT("saved_msgs"); ADD_DEF_PROMPT("no_msg"); ADD_DEF_PROMPT("in_your_voicebox"); ADD_DEF_PROMPT("and"); // Menu played after each message ADD_DEF_PROMPT("msg_menu"); // Menu played after last message ADD_DEF_PROMPT("msg_end_menu"); // Status acknowledgement ADD_DEF_PROMPT("msg_deleted"); ADD_DEF_PROMPT("msg_saved"); ADD_DEF_PROMPT("first_new_msg"); ADD_DEF_PROMPT("next_new_msg"); ADD_DEF_PROMPT("first_saved_msg"); ADD_DEF_PROMPT("next_saved_msg"); ADD_DEF_PROMPT("no_more_msg"); // # End of conversation ADD_DEF_PROMPT("bye"); if (load_digits) { ADD_DEF_PROMPT("new_msg"); ADD_DEF_PROMPT("saved_msg"); // digits from 1 to 19 for (unsigned int i=1;i<20;i++) { string str = int2str(i); if (pc->setPrompt(str, prompt_path + str + ".wav", APP_NAME) < 0) { delete pc; return NULL; } } // 20, 30, ...90 for (unsigned int i=20;i<100;i+=10) { string str = int2str(i); if (pc->setPrompt(str, prompt_path + str + ".wav", APP_NAME) < 0) { delete pc; return NULL; } } // x1 .. x9 for (unsigned int i=1;i<10;i++) { string str = "x"+int2str(i); if (pc->setPrompt(str, prompt_path + str + ".wav", APP_NAME) < 0) { delete pc; return NULL; } } } #undef ADD_DEF_PROMPT return pc; }