asr_online.h
Go to the documentation of this file.
1 
8 #ifndef ASR_ONLINE_H_
9 #define ASR_ONLINE_H_
10 #include <curl/curl.h>
11 #include "common_config.h"
12 #include "file_operation.h"
13 #include "iostream"
14 #include "linuxrec.h"
15 
17 struct AsrConfig
18 {
20  std::string api_key;
22  std::string secret_key;
24  std::string format;
26  int rate;
28  int dev_pid;
30  std::string cuid;
32  std::string scope;
34  std::string url;
35 };
36 
39 {
40 public:
48  void setAsrParams(const std::string base_path, const std::string pcm_file, const int channel);
49 
54  void initAndConfigAsr();
55 
60  void speechGetToken();
61 
66  void getPcmFileData();
67 
73  char* runAsrAndRecog();
74 
80  std::string resultFromJson();
81 
89  struct DataBuff recordThroughMIC(const float record_time, bool enable_audio_save);
90 
96  void getPCMData(struct DataBuff pcm_buff);
97 
102  void stopRecordThroughMIC();
103 
108  void uninitAsr();
109 
110 private:
116  struct DataBuff getOneChannelData();
117 
122  void saveRecordDataToFile();
123 
128  void praseToken();
129 
134  static size_t writefunc(void* ptr, size_t size, size_t nmemb, char** result);
135 
136  struct DataBuff pcm_data_ = { NULL, 0 }; // 存储pcm音频数据
137  char* rec_result_ = NULL; // 保存语音识别结果
138  std::string online_final_result;
139  std::string base_path_;
140  std::string pcm_file_;
141  int channel_;
142  int record_loops_ = 0;
143  std::string token_;
144  char* url_response_ = NULL;
145  const std::string API_TOKEN_URL = "http://openapi.baidu.com/oauth/2.0/token";
146  struct recorder* asr_record_ = NULL;
149  struct AsrConfig asr_config;
150 };
151 
152 #endif
std::string format
Definition: asr_online.h:24
FileOperation pcm_file_operation
Definition: asr_online.h:147
int rate
Definition: asr_online.h:26
std::string pcm_file_
Definition: asr_online.h:140
std::string url
Definition: asr_online.h:34
std::string cuid
Definition: asr_online.h:30
std::string token_
Definition: asr_online.h:143
std::string base_path_
Definition: asr_online.h:139
const std::string base_path
std::string api_key
Definition: asr_online.h:20
std::string online_final_result
Definition: asr_online.h:138
std::string scope
Definition: asr_online.h:32
int dev_pid
Definition: asr_online.h:28
RecordAlsaAPI record_alsa
Definition: asr_online.h:148
std::string secret_key
Definition: asr_online.h:22


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