讯飞AIUI ubuntu linux使用
简介
在AIUI平台创建应用,下载linux sdk,但是sdk默认内部录音不可用,需要修改录音输入
使用mic录音
注:data_source取值为sdk,仅在Android平台SDK下可用,其他平台只能取值user,通过外部输入音频数据。
AIUI例程修改代码
编译需要ALSA支持,因为mic输入需要
static void mic_start() { printf("mic_start "); int errcode; errcode = sr_init(&iat, NULL, SR_MIC, &recnotifier); if (errcode) { printf("speech recognizer init failed "); return; } iat.write_recorder_data = writeAudioRecord; errcode = sr_start_listening(&iat); if (errcode) { printf("start listen failed %d ", errcode); } } static void mic_stop() { printf("mic_stop "); int errcode = sr_stop_listening(&iat); if (errcode) { printf("stop listening failed %d ", errcode); } IAIUIMessage *msg = IAIUIMessage::create( AIUIConstant::CMD_STOP_WRITE, 0, 0, "data_type=audio"); agent->sendMessage(msg); msg->destroy(); sr_uninit(&iat); } // 写入测试音频 void writeAudio() { // if (NULL != agent) { // IAIUIMessage* stopMsg = // IAIUIMessage::create(AIUIConstant::CMD_START_RECORD, 0, 0, "data_type=audio"); // agent->sendMessage(stopMsg); // stopMsg->destroy(); // } mic_start(); } void stopAudio() { // if (NULL != agent) // { // IAIUIMessage *stMsg = IAIUIMessage::create(AIUIConstant::CMD_STOP_RECORD); // agent->sendMessage(stMsg); // stMsg->destroy(); // IAIUIMessage *stopMsg = // IAIUIMessage::create(AIUIConstant::CMD_STOP_SAVE, 0, 0, "data_type=raw_audio"); // agent->sendMessage(stopMsg); // stopMsg->destroy(); // } mic_stop(); }
cmakelist.txt 增加speech_recognizer.c linuxrec.c等,增加include_directories,增加target_link_libraries
上一篇:
IDEA上Java项目控制台中文乱码