Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
BaiduAsrOnline Class Reference

#include <asr_online.h>

Public Member Functions

void getPCMData (struct DataBuff pcm_buff)
 获取pcm数据接口. More...
 
void getPcmFileData ()
 读取pcm文件里的音频数据,并将数据的内容和数据大小存入pcm_data_结构体. More...
 
void initAndConfigAsr ()
 百度语音识别模块的初始化,设置asr相关参数. More...
 
struct DataBuff recordThroughMIC (const float record_time, bool enable_audio_save)
 录音接口. More...
 
std::string resultFromJson ()
 从完整的json语音识别结果中解析出需要的字符串结果. More...
 
char * runAsrAndRecog ()
 将pcm_data_结构体里存储的音频用于百度在线语音识别并获取识别结果. More...
 
void setAsrParams (const std::string base_path, const std::string pcm_file, const int channel)
 设置语音模块需外部传入的路径等参数. More...
 
void speechGetToken ()
 获取百度在线语音识别的Token. More...
 
void stopRecordThroughMIC ()
 关闭录音设备. More...
 
void uninitAsr ()
 一次识别结束后释放资源. More...
 

Private Member Functions

struct DataBuff getOneChannelData ()
 从双声道数据中分离出单声道数据. More...
 
void praseToken ()
 从json中解析出token值. More...
 
void saveRecordDataToFile ()
 把录音数据存入/cache/pcm/目录下的pcm文件里,以次序和时间命名. More...
 

Static Private Member Functions

static size_t writefunc (void *ptr, size_t size, size_t nmemb, char **result)
 libcurl 返回回调函数. More...
 

Private Attributes

const std::string API_TOKEN_URL = "http://openapi.baidu.com/oauth/2.0/token"
 
struct AsrConfig asr_config
 
struct recorderasr_record_ = NULL
 
std::string base_path_
 
int channel_
 
std::string online_final_result
 
struct DataBuff pcm_data_ = { NULL, 0 }
 
std::string pcm_file_
 
FileOperation pcm_file_operation
 
char * rec_result_ = NULL
 
RecordAlsaAPI record_alsa
 
int record_loops_ = 0
 
std::string token_
 
char * url_response_ = NULL
 

Detailed Description

百度在线语音识别模块

Definition at line 38 of file asr_online.h.

Member Function Documentation

struct DataBuff BaiduAsrOnline::getOneChannelData ( )
private

从双声道数据中分离出单声道数据.

Returns
struct DataBuff pcm_data_ - 返回单声道的pcm数据和大小.

Definition at line 164 of file asr_online.cpp.

void BaiduAsrOnline::getPCMData ( struct DataBuff  pcm_buff)

获取pcm数据接口.

Parameters
pcm_buff- [in] pcm数据的内容和数据大小.

Definition at line 158 of file asr_online.cpp.

void BaiduAsrOnline::getPcmFileData ( )

读取pcm文件里的音频数据,并将数据的内容和数据大小存入pcm_data_结构体.

Definition at line 83 of file asr_online.cpp.

void BaiduAsrOnline::initAndConfigAsr ( )

百度语音识别模块的初始化,设置asr相关参数.

Definition at line 34 of file asr_online.cpp.

void BaiduAsrOnline::praseToken ( )
private

从json中解析出token值.

Definition at line 10 of file asr_online.cpp.

struct DataBuff BaiduAsrOnline::recordThroughMIC ( const float  record_time,
bool  enable_audio_save 
)

录音接口.

Parameters
record_time- [in] 录音时长(s).
enable_audio_save- [in] 是否将录音保存到pcm文件.
Returns
struct DataBuff pcm_data_ - 返回录音的pcm数据和大小.

Definition at line 187 of file asr_online.cpp.

std::string BaiduAsrOnline::resultFromJson ( )

从完整的json语音识别结果中解析出需要的字符串结果.

Returns
std::string online_final_result - 返回解析出的字符串识别结果.

Definition at line 241 of file asr_online.cpp.

char * BaiduAsrOnline::runAsrAndRecog ( )

将pcm_data_结构体里存储的音频用于百度在线语音识别并获取识别结果.

Returns
char* rec_result_ - 返回在线语音识别的完整json结果.

Definition at line 88 of file asr_online.cpp.

void BaiduAsrOnline::saveRecordDataToFile ( )
private

把录音数据存入/cache/pcm/目录下的pcm文件里,以次序和时间命名.

Definition at line 178 of file asr_online.cpp.

void BaiduAsrOnline::setAsrParams ( const std::string  base_path,
const std::string  pcm_file,
const int  channel 
)

设置语音模块需外部传入的路径等参数.

Parameters
base_path- [in] 到/xbot_talker目录的结对路径.
pcm_file- [in] 用于进行语音识别的录音文件.
channel- [in] 音频声道数.1表示单声道,2表示双声道.

Definition at line 28 of file asr_online.cpp.

void BaiduAsrOnline::speechGetToken ( )

获取百度在线语音识别的Token.

Definition at line 55 of file asr_online.cpp.

void BaiduAsrOnline::stopRecordThroughMIC ( )

关闭录音设备.

Definition at line 261 of file asr_online.cpp.

void BaiduAsrOnline::uninitAsr ( )

一次识别结束后释放资源.

Definition at line 268 of file asr_online.cpp.

size_t BaiduAsrOnline::writefunc ( void *  ptr,
size_t  size,
size_t  nmemb,
char **  result 
)
staticprivate

libcurl 返回回调函数.

Definition at line 128 of file asr_online.cpp.

Member Data Documentation

const std::string BaiduAsrOnline::API_TOKEN_URL = "http://openapi.baidu.com/oauth/2.0/token"
private

Definition at line 145 of file asr_online.h.

struct AsrConfig BaiduAsrOnline::asr_config
private

Definition at line 149 of file asr_online.h.

struct recorder* BaiduAsrOnline::asr_record_ = NULL
private

Definition at line 146 of file asr_online.h.

std::string BaiduAsrOnline::base_path_
private

Definition at line 139 of file asr_online.h.

int BaiduAsrOnline::channel_
private

Definition at line 141 of file asr_online.h.

std::string BaiduAsrOnline::online_final_result
private

Definition at line 138 of file asr_online.h.

struct DataBuff BaiduAsrOnline::pcm_data_ = { NULL, 0 }
private

Definition at line 136 of file asr_online.h.

std::string BaiduAsrOnline::pcm_file_
private

Definition at line 140 of file asr_online.h.

FileOperation BaiduAsrOnline::pcm_file_operation
private

Definition at line 147 of file asr_online.h.

char* BaiduAsrOnline::rec_result_ = NULL
private

Definition at line 137 of file asr_online.h.

RecordAlsaAPI BaiduAsrOnline::record_alsa
private

Definition at line 148 of file asr_online.h.

int BaiduAsrOnline::record_loops_ = 0
private

Definition at line 142 of file asr_online.h.

std::string BaiduAsrOnline::token_
private

Definition at line 143 of file asr_online.h.

char* BaiduAsrOnline::url_response_ = NULL
private

Definition at line 144 of file asr_online.h.


The documentation for this class was generated from the following files:


xbot_talker
Author(s): wangxiaoyun
autogenerated on Sat Oct 10 2020 03:27:54