def query_list(self): """ 查询热词表列表信息 :return: 热词表列表信息 """ url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies' result = aksk_service.aksk_connect(self._ak, self._sk, url, None, 'GET', self._sis_config) return result
def query_by_vocabulary_id(self, vocabulary_id): """ 根据vocabulary_id查询热词表信息 :param vocabulary_id: 热词表id,使用前一定要保证其已存在。 :return: 热词表信息 """ url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies/' + vocabulary_id result = aksk_service.aksk_connect(self._ak, self._sk, url, None, 'GET', self._sis_config) return result
def get_long_response(self, job_id): """ 录音文件识别状态查询接口 :param job_id: job_id :return: 返回的结果,json格式 """ url = self._service_endpoint + '/v1/' + self._project_id + '/asr/transcriber/jobs/' + job_id result = aksk_service.aksk_connect(self._ak, self._sk, url, None, 'GET', self._sis_config) return result
def delete(self, vocabulary_id): """ 根据vocabulary_id删除指定的热词表 :param vocabulary_id: 热词表id,使用前一定要保证其已存在。 :return: 正常删除返回结果为空,出现错误则返回error_code和error_msg """ url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies/' + vocabulary_id result = aksk_service.aksk_connect(self._ak, self._sk, url, None, 'DELETE', self._sis_config) if result is None: return result result_text = result.text return json.loads(result_text)
def create(self, request): """ 创建热词表 :param request: 热词表请求 :return: 热词表id """ if not isinstance(request, HotWordRequest): logger.error('the parameter in \'create_hot_word(request)\' should be HotWordRequest class') raise ClientException('the parameter in \'create_hot_word(request)\' should be HotWordRequest class') url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies' params = request.construct_params() result = aksk_service.aksk_connect(self._ak, self._sk, url, params, 'POST', self._sis_config) return result
def assessment_video(self, request): """ 多模态评测接口 :param request: 多模态评测请求 :return: 响应结果,返回为json格式 """ if not isinstance(request, PaVideoRequest): error_msg = 'the parameter in \'assessment_video(request)\' should be PaVideoRequest class' logger.error(error_msg) raise ClientException(error_msg) url = self._service_endpoint + '/v1/' + self._project_id + '/assessment/video' params = request.construct_parameter() result = aksk_service.aksk_connect(self._ak, self._sk, url, params, 'POST', self._sis_config) return result
def get_short_response(self, request): """ 一句话识别接口 :param request: 一句话识别请求AsrCustomShortRequest :return: 一句话识别响应结果,返回为json格式 """ if not isinstance(request, AsrCustomShortRequest): error_msg = 'the parameter in \'get_short_response(request)\' should be AsrCustomShortRequest class' logger.error(error_msg) raise ClientException(error_msg) url = self._service_endpoint + '/v1/' + self._project_id + '/asr/short-audio' params = request.construct_params() result = aksk_service.aksk_connect(self._ak, self._sk, url, params, 'POST', self._sis_config) return result
def get_asr_response(self, request): """ 短语音识别接口 :param request: 短语音识别请求 AsrRequest :return: 短语音识别响应,json格式 """ if not isinstance(request, AsrRequest): logger.error( 'the parameter in \'get_asr_response(request)\' should be AsrRequest class' ) raise ClientException( 'the parameter in \'get_asr_response(request)\' should be AsrRequest class' ) url = self._service_endpoint + '/v1.0/voice/asr/sentence' params = request.construct_params() result = aksk_service.aksk_connect(self._ak, self._sk, url, params, 'POST', self._sis_config) return result
def submit_job(self, request): """ 录音文件识别,提交任务接口 :param request: 录音文件识别请求 :return: job_id """ if not isinstance(request, AsrCustomLongRequest): error_msg = 'the parameter in \'submit_job(request)\' should be AsrCustomLongRequest class' logger.error(error_msg) raise ClientException(error_msg) url = self._service_endpoint + '/v1/' + self._project_id + '/asr/transcriber/jobs' params = request.construct_parameter() result = aksk_service.aksk_connect(self._ak, self._sk, url, params, 'POST', self._sis_config) if 'job_id' not in result: error_msg = 'The result of long audio transcription doesn\'t contain key job_id, result is ' % result logger.error(error_msg) raise ClientException(error_msg) return result['job_id']
def get_ttsc_response(self, request): """ 定制语音合成接口 :param request: 定制语音合成请求,TtsCustomRequest :return: 请求结果,json格式 """ if not isinstance(request, TtsCustomRequest): logger.error('the parameter in \'get_ttsc_response(request)\' should be TtsCustomRequest class') raise ClientException('the parameter in \'get_ttsc_response(request)\' should be TtsCustomRequest class') url = self._service_endpoint + '/v1/' + self._project_id + '/tts' params = request.construct_params() result = aksk_service.aksk_connect(self._ak, self._sk, url, params, 'POST', self._sis_config) if 'result' not in result: error_msg = 'The result of tts customization is invalid. Result is %s ' % json.dumps(result) logger.error(error_msg) raise ClientException(error_msg) if request.get_saved(): base_str = result['result']['data'] io_utils.save_audio_from_base64str(base_str, request.get_saved_path()) result['is_saved'] = True result['saved_path'] = request.get_saved_path() return result