21 ROS_INFO_STREAM(
"Offline asr result is :" << recog_result << std::endl);
22 std::ofstream result_log(
log_path +
"/test_result_log.txt", std::ios::app);
23 if (result_log.is_open())
25 result_log <<
count <<
"\n" << recog_result << std::endl;
39 char* recog_result_online;
41 ROS_INFO_STREAM(
"Online asr result is :" << recog_result_online << std::endl);
42 std::ofstream result_log(
log_path +
"/test_online_result_log.txt", std::ios::app);
43 if (result_log.is_open())
45 result_log <<
count <<
"\n" << recog_result_online << std::endl;
54 int main(
int argc,
char** argv)
56 setlocale(LC_ALL,
"");
60 std::string asr_params_;
61 std::string grammar_path;
64 std::string test_dir_path;
69 asr_nodehandle.
param(
"/asr_sample/enable_online", enable_online,
bool(
false));
70 asr_nodehandle.
param(
"/asr_sample/enable_offline", enable_offline,
bool(
true));
72 asr_nodehandle.
param(
"/asr_sample/base_path",
base_path, std::string(
"~/catkin_ws/src/xbot_talker"));
73 asr_nodehandle.
param(
"/asr_sample/test_dir_path", test_dir_path, std::string(
"~/catkin_ws/src/xbot_talker"));
74 asr_nodehandle.
param(
"/asr_sample/grammar_path", grammar_path,
75 std::string(
"~/catkin_ws/src/xbot_talker/cache/grammar_config"));
76 asr_nodehandle.
param(
"/asr_sample/pcm_file", pcm_file,
77 std::string(
"~/catkin_ws/src/xbot_talker/defaultconfig/audio/nihao_test.pcm"));
79 asr_nodehandle.
param(
"/asr_sample/log_path",
log_path, std::string(
"~/catkin_ws/src/xbot_talker/cache/log"));
81 asr_nodehandle.
param(
"/asr_sample/audio_channel", audio_channel,
int(1));
83 if (enable_offline ==
true)
91 if (enable_online ==
true)
96 std::cout <<
"Test dir is :" << test_dir_path << std::endl;
98 std::vector<std::string> files;
101 for (
int i = 0; i < files.size(); i++)
106 if (enable_offline && enable_online)
114 offlineThread.join();
116 else if (enable_offline ==
true)
121 offlineThread.join();
123 else if (enable_online ==
true)
131 std::cout << files[i] << std::endl;
void initAsr()
科大讯飞识别模块的初始化.
static CommonConfig & get_instance()
void initAndConfigAsr()
百度语音识别模块的初始化,设置asr相关参数.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void uninitAsr()
一次识别结束后释放资源.
void loginToXunfei(const std::string base_path)
科大讯飞语音识别模块接口头文件. TODO: 还需要添加版权、版本等信息
void setAsrParams(const std::string base_path, const std::string pcm_file, const int channel)
设置语音模块需外部传入的路径等参数.
void uninitAsr()
一次识别结束后释放资源.
百度语音识别模块接口头文件. TODO: 还需要添加版权、版本等信息
char * dataLoopRecog()
将全部音频数据循环写入科大讯飞接口进行识别并获取完整的json识别结果.
XfeiSpeechRecog asr_module
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void setAsrParams(const std::string base_path, const std::string pcm_file, const std::string params, const int channel)
设置语音模块需外部传入的路径等参数.
char * runAsrAndRecog()
将pcm_data_结构体里存储的音频用于百度在线语音识别并获取识别结果.
BaiduAsrOnline asr_online_module
void speechGetToken()
获取百度在线语音识别的Token.
int main(int argc, char **argv)
#define ROS_INFO_STREAM(args)
std::string configGramParas(const std::string base_path, const std::string grammar_file)
#define ROS_ERROR_STREAM(args)
void getPcmFileData()
读取pcm文件里的音频数据,并将数据的内容和数据大小存入pcm_data_结构体.
void getPcmFileData()
读取pcm文件里的音频数据,并将数据的内容和数据大小存入pcm_data_.
void getAllFilesName(std::string dir_path, std::vector< std::string > &files_name)