17 std::cout <<
"--------- baidu asr demo ------------" << std::endl;
18 std::cout <<
"这是百度在线语音识别的示例demo.\n你可以选择通过已录好的pcm文件或者实时录音进行测试." << std::endl;
19 std::cout <<
"0:选择已录好的pcm音频文件进行测试;" << std::endl;
20 std::cout <<
"1:通过实时录音进行测试." << std::endl;
21 std::cout <<
"请输入0或1选择不同方式:" << std::endl;
22 std::cout <<
"asr_mode :_\b";
38 char* recog_result_online;
42 std::string baidu_online_result = baidu_sr_online.
resultFromJson();
43 std::cout <<
"Online asr result is :" << recog_result_online << std::endl;
44 std::cout <<
"Online asr finall result is :" << baidu_online_result << std::endl;
60 float record_time = 3.5;
62 bool enable_record_save =
true;
63 struct DataBuff pcm_buff = { NULL, 0 };
65 pcm_buff = baidu_sr_online.
recordThroughMIC(record_time, enable_record_save);
68 char* recog_result_online;
72 std::string baidu_online_result = baidu_sr_online.
resultFromJson();
73 std::cout <<
"Online asr result is :" << recog_result_online << std::endl;
74 std::cout <<
"Online asr finall result is :" << baidu_online_result << std::endl;
78 int main(
int argc,
char** argv)
83 const std::string default_pcm_file =
base_path +
"/defaultconfig/audio/nihao_test.pcm";
88 std::cout <<
"请输入用于测试的pcm文件,若输入为d,则用默认的文件进行测试:";
92 pcm_file = default_pcm_file;
103 std::cout <<
"无效的awaken_mode模式的选择!!!" << std::endl;
void initAndConfigAsr()
百度语音识别模块的初始化,设置asr相关参数.
void setAsrParams(const std::string base_path, const std::string pcm_file, const int channel)
设置语音模块需外部传入的路径等参数.
int main(int argc, char **argv)
void uninitAsr()
一次识别结束后释放资源.
百度语音识别模块接口头文件. TODO: 还需要添加版权、版本等信息
void fileToASR(const std::string pcm_file)
std::string resultFromJson()
从完整的json语音识别结果中解析出需要的字符串结果.
char * runAsrAndRecog()
将pcm_data_结构体里存储的音频用于百度在线语音识别并获取识别结果.
void recordToASR(const std::string pcm_file)
void speechGetToken()
获取百度在线语音识别的Token.
const std::string base_path
struct DataBuff recordThroughMIC(const float record_time, bool enable_audio_save)
录音接口.
void usage(int &asr_mode)
void getPcmFileData()
读取pcm文件里的音频数据,并将数据的内容和数据大小存入pcm_data_结构体.
void getPCMData(struct DataBuff pcm_buff)
获取pcm数据接口.