|
| 1 | +/* |
| 2 | + * Tencent is pleased to support the open source community by making IoT Hub |
| 3 | + available. |
| 4 | + * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. |
| 5 | +
|
| 6 | + * Licensed under the MIT License (the "License"); you may not use this file |
| 7 | + except in |
| 8 | + * compliance with the License. You may obtain a copy of the License at |
| 9 | + * http://opensource.org/licenses/MIT |
| 10 | +
|
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is |
| 13 | + * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | + KIND, |
| 15 | + * either express or implied. See the License for the specific language |
| 16 | + governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * |
| 19 | + */ |
| 20 | + |
| 21 | +#ifndef QCLOUD_IOT_EXPORT_ASR_H_ |
| 22 | +#define QCLOUD_IOT_EXPORT_ASR_H_ |
| 23 | + |
| 24 | +#ifdef __cplusplus |
| 25 | +extern "C" { |
| 26 | +#endif |
| 27 | + |
| 28 | +#include "qcloud_iot_import.h" |
| 29 | + |
| 30 | +#define REAL_TIME_SLICE_FILE_NAME_LEN (64) |
| 31 | +#define VOICE_ID_LEN (16) |
| 32 | + |
| 33 | +// refer to https://cloud.tencent.com/document/product/1093/37823#2.-.E8.BE.93.E5.85.A5.E5.8F.82.E6.95.B0 |
| 34 | +typedef enum { |
| 35 | + eENGINE_8K_EN = 0, |
| 36 | + eENGINE_8K_ZH = 1, |
| 37 | + eENGINE_8K_ZH_S = 2, |
| 38 | + eENGINE_16K_ZH = 3, |
| 39 | + eENGINE_16K_ZH_VIDEO = 4, |
| 40 | + eENGINE_16K_EN = 5, |
| 41 | + eENGINE_16K_CA = 6, |
| 42 | + eENGINE_16K_JA = 7, |
| 43 | + eENGINE_16K_WUU_SH = 8, |
| 44 | + eENGINE_DEFAULT = 9, |
| 45 | +} eAsrEngineType; |
| 46 | + |
| 47 | +typedef enum { |
| 48 | + eASR_FILE = 0, |
| 49 | + eASR_REALTIME = 1, |
| 50 | + eASR_SENTENCE = 2, |
| 51 | +} eAsrType; |
| 52 | + |
| 53 | +typedef enum { |
| 54 | + eVOICE_WAVE = 1, |
| 55 | + eVOICE_SPEEX = 4, |
| 56 | + eVOICE_SILK = 6, |
| 57 | + eVOICE_MP3 = 8, |
| 58 | + eVOICE_OPUS = 10, |
| 59 | +} eVoiceType; |
| 60 | + |
| 61 | +typedef enum { |
| 62 | + eRESPONSE_PER_SLICE = 0, |
| 63 | + eRESPONSE_END = 1, |
| 64 | +} eResType; |
| 65 | + |
| 66 | +typedef struct _RecordAsrConf_ { |
| 67 | + uint32_t request_timeout_ms; |
| 68 | + |
| 69 | + // Required parameters |
| 70 | + eAsrType req_type; |
| 71 | + eAsrEngineType engine_type; |
| 72 | + int ch_num; |
| 73 | + |
| 74 | + // Optional parameters |
| 75 | + int filter_dirty; |
| 76 | + int filter_modal; |
| 77 | + int filter_punc; |
| 78 | + int convert_num_mode; |
| 79 | + int speaker_diarization; |
| 80 | + int speaker_number; |
| 81 | + char *hot_word_id; |
| 82 | +} RecordAsrConf; |
| 83 | + |
| 84 | +// refer to https://cloud.tencent.com/document/product/1093/35799#.E8.AF.B7.E6.B1.82.E7.BB.93.E6.9E.84 |
| 85 | +typedef struct _RealTimeAsrConf_ { |
| 86 | + uint32_t request_timeout_ms; |
| 87 | + char file_name[REAL_TIME_SLICE_FILE_NAME_LEN]; |
| 88 | + |
| 89 | + // Required parameters |
| 90 | + eAsrType req_type; |
| 91 | + eAsrEngineType engine_type; |
| 92 | + eResType res_type; |
| 93 | + eVoiceType voice_format; |
| 94 | + char voice_id[VOICE_ID_LEN + 1]; |
| 95 | + int seq; |
| 96 | + int end; |
| 97 | + |
| 98 | + // Optional parameters |
| 99 | + int need_vad; |
| 100 | + int vad_silence_time; |
| 101 | + int filter_dirty; |
| 102 | + int filter_modal; |
| 103 | + int filter_punc; |
| 104 | + int convert_num_mode; |
| 105 | + char *hot_word_id; |
| 106 | +} RealTimeAsrConf; |
| 107 | + |
| 108 | +typedef void (*OnAsrResultCB)(uint32_t request_id, char *res_text, int total_resutl_num, int resutl_seq); |
| 109 | + |
| 110 | +typedef int (*OnAsrResourceEventUsrCallback)(void *pContext, const char *msg, uint32_t msgLen, int event); |
| 111 | + |
| 112 | +/** |
| 113 | + * @brief Init asr client |
| 114 | + * MQTT Client should be constructed beforehand |
| 115 | + * |
| 116 | + * @param product_id: product Id |
| 117 | + * @param device_name: device name |
| 118 | + * @param pTemplate_client: data template client |
| 119 | + * @param usr_cb: user callback |
| 120 | + * |
| 121 | + * @return a valid asr client handle when success, or NULL otherwise |
| 122 | + */ |
| 123 | +void *IOT_Asr_Init(const char *product_id, const char *device_name, void *pTemplate_client, |
| 124 | + OnAsrResourceEventUsrCallback usr_cb); |
| 125 | + |
| 126 | +/** |
| 127 | + * @brief Destroy asr client |
| 128 | + * |
| 129 | + * @param handle: asr client handle |
| 130 | + * |
| 131 | + * @return QCLOUD_RET_SUCCESS when success, or err code for failure |
| 132 | + */ |
| 133 | +int IOT_Asr_Destroy(void *handle); |
| 134 | + |
| 135 | +/** |
| 136 | + * @brief Record file asr request |
| 137 | + * |
| 138 | + * @param handle: asr client handle |
| 139 | + * |
| 140 | + * @param file_name: record file name with path |
| 141 | + * |
| 142 | + * @param conf: record file parameter and request conf |
| 143 | + * |
| 144 | + * @param cb: callback function when asr result received |
| 145 | + * |
| 146 | + * @return QCLOUD_RET_SUCCESS when success, or err code for failure |
| 147 | + */ |
| 148 | +int IOT_Asr_RecordFile_Request(void *handle, const char *file_name, RecordAsrConf *conf, OnAsrResultCB cb); |
| 149 | + |
| 150 | +/** |
| 151 | + * @brief Realtime asr |
| 152 | + * |
| 153 | + * @param handle: asr client handle |
| 154 | + * |
| 155 | + * @param audio_buff: audio data with encoding,like wav/speex/silk/mp3/opus |
| 156 | + * |
| 157 | + * @param audio_data_len: audio data len |
| 158 | + * |
| 159 | + * @param conf: real time audio data parameter and request conf |
| 160 | + * |
| 161 | + * @param cb: callback function when asr result received |
| 162 | + * |
| 163 | + * @return QCLOUD_RET_SUCCESS when success, or err code for failure |
| 164 | + */ |
| 165 | +int IOT_Asr_Realtime_Request(void *handle, char *audio_buff, uint32_t audio_data_len, RealTimeAsrConf *conf, |
| 166 | + OnAsrResultCB cb); |
| 167 | +#ifdef __cplusplus |
| 168 | +} |
| 169 | +#endif |
| 170 | + |
| 171 | +#endif /* QCLOUD_IOT_EXPORT_OTA_H_ */ |
0 commit comments