|
| 1 | +# -*- coding=utf-8 |
| 2 | + |
| 3 | +from qcloud_cos import CosS3Auth |
| 4 | +from qcloud_cos.cos_client import logger, CosS3Client |
| 5 | +from .cos_comm import * |
| 6 | + |
| 7 | + |
| 8 | +class IntelligentSpeechClient(CosS3Client): |
| 9 | + |
| 10 | + def _asr_hot_vocabulary_table(self, Bucket, Body=None, Params={}, Path="/asrhotvocabtable", Method="POST", **kwargs): |
| 11 | + headers = mapped(kwargs) |
| 12 | + final_headers = {} |
| 13 | + params = Params |
| 14 | + for key in headers: |
| 15 | + if key.startswith("response"): |
| 16 | + params[key] = headers[key] |
| 17 | + else: |
| 18 | + final_headers[key] = headers[key] |
| 19 | + headers = final_headers |
| 20 | + params = format_values(params) |
| 21 | + |
| 22 | + xml_config = None |
| 23 | + if Body is not None: |
| 24 | + xml_config = format_xml(data=Body, root='Request') |
| 25 | + path = Path |
| 26 | + url = self._conf.uri(bucket=Bucket, path=path, endpoint=self._conf._endpoint_ci) |
| 27 | + logger.info("_asr_hot_vocabulary_table result, url=:{url} ,headers=:{headers}, params=:{params}, xml_config=:{xml_config}".format( |
| 28 | + url=url, |
| 29 | + headers=headers, |
| 30 | + params=params, |
| 31 | + xml_config=xml_config)) |
| 32 | + rt = self.send_request( |
| 33 | + method=Method, |
| 34 | + url=url, |
| 35 | + bucket=Bucket, |
| 36 | + data=xml_config, |
| 37 | + auth=CosS3Auth(self._conf, path, params=params), |
| 38 | + params=params, |
| 39 | + headers=headers, |
| 40 | + ci_request=True, |
| 41 | + cos_request=False) |
| 42 | + |
| 43 | + data = rt.content |
| 44 | + response = dict(**rt.headers) |
| 45 | + if 'Content-Type' in response and len(data) != 0: |
| 46 | + if response['Content-Type'] == 'application/xml': |
| 47 | + data = xml_to_dict(rt.content) |
| 48 | + format_dict(data, ['Response']) |
| 49 | + elif response['Content-Type'].startswith('application/json'): |
| 50 | + data = rt.json() |
| 51 | + |
| 52 | + return response, data |
| 53 | + |
| 54 | + def ci_create_asr_hot_vocabulary_table(self, Bucket, Body, **kwargs): |
| 55 | + """ |
| 56 | +
|
| 57 | + :param Bucket(string): 存储桶名称 |
| 58 | + :param Body(dict): 创建热词表body |
| 59 | + :param kwargs(dict): 设置请求的headers. |
| 60 | + :return(dict): 创建成功返回的结果, dict类型. |
| 61 | +
|
| 62 | + . code-block:: python |
| 63 | +
|
| 64 | + body = { |
| 65 | + "TableName": "test", |
| 66 | + "TableDescription": "test", |
| 67 | + "VocabularyWeights": { |
| 68 | + "Vocabulary": "abc", |
| 69 | + "Weight": "10" |
| 70 | + }, |
| 71 | + # "VocabularyWeightStr": "" |
| 72 | + } |
| 73 | + response, data = client.ci_create_asr_hot_vocabulary_table( |
| 74 | + Bucket=bucket_name, |
| 75 | + Body=body, |
| 76 | + ContentType='application/xml' |
| 77 | + ) |
| 78 | + print(response) |
| 79 | + print(data) |
| 80 | + return response, data |
| 81 | + """ |
| 82 | + return self._asr_hot_vocabulary_table(Bucket, Body, **kwargs) |
| 83 | + |
| 84 | + def ci_update_asr_hot_vocabulary_table(self, Bucket, Body, **kwargs): |
| 85 | + """ |
| 86 | +
|
| 87 | + :param Bucket(string): 存储桶名称 |
| 88 | + :param Body(dict): 更新热词表body |
| 89 | + :param kwargs(dict): 设置请求的headers. |
| 90 | + :return(dict): 更新成功返回的结果, dict类型. |
| 91 | +
|
| 92 | + . code-block:: python |
| 93 | +
|
| 94 | + body = { |
| 95 | + "TableId": "08417b95c91xxxxxxxxxxxxx", |
| 96 | + "TableName": "test1", |
| 97 | + "TableDescription": "test1", |
| 98 | + "VocabularyWeights": { |
| 99 | + "Vocabulary": "abc", |
| 100 | + "Weight": "8" |
| 101 | + }, |
| 102 | + # "VocabularyWeightStr": "" |
| 103 | + } |
| 104 | + response, data = client.ci_update_asr_hot_vocabulary_table( |
| 105 | + Bucket=bucket_name, |
| 106 | + Body=body, |
| 107 | + ContentType='application/xml' |
| 108 | + ) |
| 109 | + print(response) |
| 110 | + print(data) |
| 111 | + return response, data |
| 112 | + """ |
| 113 | + return self._asr_hot_vocabulary_table(Bucket=Bucket, Body=Body, Method="PUT", **kwargs) |
| 114 | + |
| 115 | + def ci_get_asr_hot_vocabulary_table(self, Bucket, TableId, **kwargs): |
| 116 | + """ |
| 117 | +
|
| 118 | + :param Bucket(string): 存储桶名称 |
| 119 | + :param TableId(string): 热词表ID |
| 120 | + :param kwargs(dict): 设置请求的headers. |
| 121 | + :return(dict): 查询成功返回的结果, dict类型. |
| 122 | +
|
| 123 | + . code-block:: python |
| 124 | +
|
| 125 | + response, data = client.ci_get_asr_hot_vocabulary_table( |
| 126 | + Bucket=bucket_name, |
| 127 | + TableId='08417b95c91xxxxxxxxxxxxx', |
| 128 | + ) |
| 129 | + print(response) |
| 130 | + print(data) |
| 131 | + return response, data |
| 132 | + """ |
| 133 | + return self._asr_hot_vocabulary_table(Bucket=Bucket, Method="GET", Path="/asrhotvocabtable/" + TableId, **kwargs) |
| 134 | + |
| 135 | + def ci_list_asr_hot_vocabulary_table(self, Bucket, Offset=0, Limit=10, **kwargs): |
| 136 | + """ |
| 137 | +
|
| 138 | + :param Bucket(string): 存储桶名称 |
| 139 | + :param Offset(string): 热词表ID |
| 140 | + :param Limit(string): 热词表ID |
| 141 | + :param kwargs(dict): 设置请求的headers. |
| 142 | + :return(dict): 查询成功返回的结果, dict类型. |
| 143 | +
|
| 144 | + . code-block:: python |
| 145 | +
|
| 146 | + response, data = client.ci_list_asr_hot_vocabulary_table( |
| 147 | + Bucket=bucket_name, |
| 148 | + ) |
| 149 | + print(response) |
| 150 | + print(data) |
| 151 | + return response, data |
| 152 | + """ |
| 153 | + param = {} |
| 154 | + param["offset"] = Offset |
| 155 | + param["limit"] = Limit |
| 156 | + return self._asr_hot_vocabulary_table(Bucket=Bucket, Method="GET", Params=param, **kwargs) |
| 157 | + |
| 158 | + def ci_delete_asr_hot_vocabulary_table(self, Bucket, TableId, **kwargs): |
| 159 | + """ |
| 160 | +
|
| 161 | + :param Bucket(string): 存储桶名称 |
| 162 | + :param TableId(string): 热词表ID |
| 163 | + :param kwargs(dict): 设置请求的headers. |
| 164 | + :return(dict): 查询成功返回的结果, dict类型. |
| 165 | +
|
| 166 | + . code-block:: python |
| 167 | +
|
| 168 | + response, data = client.ci_delete_asr_hot_vocabulary_table( |
| 169 | + Bucket=bucket_name, |
| 170 | + TableId='08417b95c91xxxxxxxxxxxxx', |
| 171 | + ) |
| 172 | + print(response) |
| 173 | + print(data) |
| 174 | + return response, data |
| 175 | + """ |
| 176 | + return self._asr_hot_vocabulary_table(Bucket=Bucket, Method="DELETE", Path="/asrhotvocabtable/" + TableId, **kwargs) |
0 commit comments