2 #include <boost/thread.hpp> 29 std::cout <<
"QISRSessionBegin failed : errorcode:" << error_code << std::endl;
47 std::cout <<
"QIVWAudioWrite failed! error code:" << err_code << std::endl;
55 const char* qisr_result = NULL;
64 std::cout <<
"QISRGetResult failed ! errorcode:" << ret << std::endl;
67 if (qisr_result != NULL)
72 std::cout <<
"\n Malloc failed in rec_result !!!\n";
99 bool is_last_audio =
false;
116 std::cout <<
"-----------Start Recognizing--------" << std::endl;
120 const unsigned int default_wave_len = 6400;
121 unsigned int wave_len = default_wave_len;
127 is_last_audio =
true;
136 pcm_index += wave_len;
162 std::cout <<
"QISRSessionEnd failed !errorcode:" << ret << std::endl;
182 if (doc.HasParseError())
185 std::cout <<
"JSON解析错误" << code << std::endl;
193 for (
int i = 0; i < wordArr.Size(); ++i)
196 if (wordUnit.HasMember(
"cw"))
217 std::string save_file =
base_path_ +
"/cache/pcm" + save_file_name;
218 std::ofstream pcm_file(save_file, std::ofstream::binary);
225 int success_code = 0;
227 std::cout <<
"-----------Start ASR Recording Thread --------" << std::endl;
235 std::cout <<
"\nNo active record device find! ";
239 std::cout <<
"The total number of active input devices is : " <<
getInputDeviceNum() << std::endl;
245 std::cout <<
"\n Malloc failed in asr_record_ !!!\n";
263 int speech_count = 0;
264 bool is_speech =
false;
265 bool is_speech_end =
false;
266 float backgrand_energy = 0;
270 float level_energy = 0;
274 backgrand_energy = VDA_detec.
levelEnergy(record_pcm, 15);
279 level_energy = VDA_detec.
levelEnergy(record_pcm, 15);
283 if ((level_energy - backgrand_energy) > 2.2)
287 if (speech_count >= 30)
291 if ((buf_count >= 450) && (is_speech ==
true) && (buf_count <= 550))
293 if (level_energy < (backgrand_energy + 1))
299 is_speech_end =
true;
302 if (is_speech_end ==
true)
304 std::cout <<
"speech done!" << std::endl;
312 std::cout <<
"ERROR:buf_new realloc error!" << std::endl;
322 if (enable_audio_save)
325 save_pcm_to_file.detach();
int MSPAPI QISRSessionEnd(const char *sessionID, const char *hints)
struct DataBuff startRecord()
struct speech_recog speech_recog_
struct recorder * asr_record_
void initAsr()
科大讯飞识别模块的初始化.
FileOperation pcm_file_operation
static CommonConfig & get_instance()
void uninitAsr()
一次识别结束后释放资源.
char * getRecogResultLoop()
获取完整的json语音识别结果.
const char *MSPAPI QISRSessionBegin(const char *grammarList, const char *params, int *errorCode)
科大讯飞语音识别模块接口头文件. TODO: 还需要添加版权、版本等信息
static const int BUFFER_SIZE
int setRecordDuration(const float duration_time)
std::string setFileName(std::string file_type)
char * dataLoopRecog()
将全部音频数据循环写入科大讯飞接口进行识别并获取完整的json识别结果.
std::vector< std::string > recog_result_vector
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
void writeAudioData(const char *audio_data, unsigned int audio_len)
将pcm音频写入科大讯飞QISRAudioWrite接口.
struct DataBuff recordThroughMIC(const float record_time, bool enable_audio_save)
录音接口.
ParseErrorCode
Error code of parsing.
iFLY Speech Recognizer Header File
void initRecord(struct recorder *rec, record_dev_id dev, WAVEFORMATEX *fmt)
float levelEnergy(struct DataBuff pcm_data, const int call_count)
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
void setAsrParams(const std::string base_path, const std::string pcm_file, const std::string params, const int channel)
设置语音模块需外部传入的路径等参数.
record_dev_id getDefaultInputDevice()
std::string final_recog_result_
const std::string base_path
void stopRecordThroughMIC()
关闭录音设备.
RecordAlsaAPI record_alsa
const char *MSPAPI QISRGetResult(const char *sessionID, int *rsltStatus, int waitTime, int *errorCode)
void saveRecordDataToFile()
把录音数据存入/cache/pcm/目录下的pcm文件里,以次序和时间命名.
int MSPAPI QISRAudioWrite(const char *sessionID, const void *waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus)
std::string pcm_file_path
struct DataBuff getOneChannelData()
从双声道数据中分离出单声道数据.
std::vector< std::string > resultFromJson()
从完整的json语音识别结果中解析出需要的字符串结果和置信度值.
void getPcmFileData()
读取pcm文件里的音频数据,并将数据的内容和数据大小存入pcm_data_.
void getPCMData(struct DataBuff pcm_buff)
获取pcm数据接口.
struct DataBuff pcm_data_
struct DataBuff readFileAsDatabuffer(const std::string file_path)