20 std::string dialogue_prompt_wav =
"play " +
base_path_ +
"/defaultconfig/audio/call.wav";
21 system(dialogue_prompt_wav.c_str());
39 std::string login_parameters =
"appid = 5ade9569, work_dir = " + base_path +
"/defaultconfig";
40 int error_code =
MSPLogin(NULL, NULL, login_parameters.c_str());
43 std::cout <<
"MSPLogin failed ! errorcode:" << error_code << std::endl;
47 "=fo|res/ivw/wakeupresource.jet";
60 std::cout <<
"QIVWSessionEnd failed !errorcode:" << ret << std::endl;
92 std::cout <<
"QIVWAudioWrite failed! error code:" << err_code << std::endl;
109 std::cout <<
"\nMSP_IVW_MSG_ERROR errCode = " << param1 << std::endl;
115 std::cout <<
"\nMSP_IVW_MSG_WAKEUP result = " << (
const char*)info << std::endl;
118 awaken_result_ = NULL;
129 std::cout <<
"QIVWSessionBegin failed! error code:" << err_code << std::endl;
136 std::cout <<
"QIVWRegisterNotify failed! error code:" << err_code << std::endl;
145 long audio_count = 0;
162 if (0 == audio_count)
181 std::string save_file =
base_path_ +
"/cache/pcm" + save_file_name;
182 std::ofstream pcm_file(save_file, std::ofstream::binary);
189 int success_code = 0;
193 std::cout <<
"-----------Start Voice Wake up Thread --------" << std::endl;
201 std::cout <<
"\nNo active record device find! ";
205 std::cout <<
"The total number of active input devices is : " <<
getInputDeviceNum() << std::endl;
231 std::cout <<
"ERROR:buf_new realloc error!" << std::endl;
int MSPAPI QIVWRegisterNotify(const char *sessionID, ivw_ntf_handler msgProcCb, void *userData)
void checkIsAwaken()
检测是否唤醒.
struct DataBuff startRecord()
void recordThroughMIC(const float record_time, bool enable_audio_save)
录音并进行语音唤醒.
int MSPAPI MSPLogin(const char *usr, const char *pwd, const char *params)
科大讯飞离线唤醒模块接口定义头文件. TODO: 还需要添加版权、版本等信息
void writeAudioData(const char *audio_data, unsigned int audio_len)
将pcm音频写入科大讯飞QIVWAudioWrite接口.
void dataLoopAwaken()
将音频数据循环写入科大讯飞接口进行离线唤醒.
int setRecordDuration(const float duration_time)
void uninitAsr()
一次离线唤醒结束后释放资源.
void awakenInit()
科大讯飞离线唤醒模块的初始化.
std::string setFileName(std::string file_type)
int MSPAPI QIVWSessionEnd(const char *sessionID, const char *hints)
struct recorder * awaken_record_
Mobile Speech Platform Common Interface Header File.
void initRecord(struct recorder *rec, record_dev_id dev, WAVEFORMATEX *fmt)
int MSPAPI QIVWAudioWrite(const char *sessionID, const void *audioData, unsigned int audioLen, int audioStatus)
void getPcmFileData()
读取pcm文件里的音频数据,并将数据的内容和数据大小存入pcm_data_结构体.
const char * awaken_params_
record_dev_id getDefaultInputDevice()
void loginAndSetParams(const std::string base_path, const std::string pcm_file, const int channel)
科大讯飞离线唤醒登录以及参数设置.
static int cb_ivw_msg_proc(const char *sessionID, int msg, int param1, int param2, const void *info, void *userData)
static char * awaken_result_
void saveRecordDataToFile()
把录音数据存入/cache/pcm/目录下的pcm文件里,以次序和时间命名.
const std::string base_path
void stopRecordThroughMIC()
关闭录音设备.
struct DataBuff getOneChannelData()
FileOperation file_operation
const char *MSPAPI QIVWSessionBegin(const char *grammarList, const char *params, int *errorCode)
RecordAlsaAPI record_alsa
std::string pcm_file_path
struct DataBuff pcm_data_
struct DataBuff readFileAsDatabuffer(const std::string file_path)