日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

創建熱詞詞表

本文主要介紹如何通過API創建熱詞詞表。

請求參數

功能名稱

參數

類型

默認值

說明

詞表名稱

Name

string

-

必選,請設置熱詞詞表的名稱。

詞表描述

Description

string

-

用于記錄詞表的具體信息。

熱詞權重

WordWeights

string

-

必選,詞表里的詞和對應的權重,為JSON的Map格式字符串。例如:

{
 "蘋果":2,
 "西瓜":2
}

key為String類型的熱詞,value為Int類型的熱詞對應的權重。

說明
  • 權重取值范圍[-6,5]。

  • 取值大于0會增大該詞語被識別的概率,小于0會減小該詞語被識別的概率。

  • 取值為-6:表示盡量不要識別出該詞語。

  • 取值為2:常用值。

  • 如果效果不明顯,可以適當增加權重,但是當權重較大時可能會引起負面效果,導致其他詞語識別不準確。

示例代碼

#!/usr/bin/env python
#coding=utf-8

import os
import json
import datetime
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
from aliyunsdkcore.auth.credentials import AccessKeyCredential

def create_common_request(domain, version, protocolType, method, uri):
    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain(domain)
    request.set_version(version)
    request.set_protocol_type(protocolType)
    request.set_method(method)
    request.set_uri_pattern(uri)
    request.add_header('Content-Type', 'application/json')
    return request

def init_parameters():
    root = dict()
    root['Name'] = '輸入您的詞表名稱'
    root['Description'] = '輸入您的詞表描述'

    words = dict()
    words['蘋果'] = 3
    words['西瓜'] = 3
    root['WordWeights'] = words

    return root

body = init_parameters()
print(body)

# TODO  請通過環境變量設置您的 AccessKeyId 和 AccessKeySecret
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
client = AcsClient(region_id='cn-beijing', credential=credentials)

request = create_common_request('tingwu.cn-beijing.aliyuncs.com', '2023-09-30', 'https', 'POST', '/openapi/tingwu/v2/resources/phrases')

request.set_content(json.dumps(body).encode('utf-8'))
response = client.do_action_with_exception(request)
print("response: \n" + json.dumps(json.loads(response), indent=4, ensure_ascii=False))
package com.alibaba.tingwu.client.demo.offlinetask;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import org.junit.Test;

/**
 * @author tingwu2023
 * @desc 創建熱詞詞表demo。
 */
public class CreateTranscriptionPhrasesTest {

    @Test
    public void summitTask() throws ClientException {
        CommonRequest request = createCommonRequest("tingwu.cn-beijing.aliyuncs.com", "2023-09-30", ProtocolType.HTTPS, MethodType.POST, "/openapi/tingwu/v2/resources/phrases");

        JSONObject root = new JSONObject();
        root.put("Name", "輸入您的熱詞詞表名稱");
        root.put("Description", "輸入您的熱詞詞表描述");

        JSONObject wordWeights = new JSONObject();
        wordWeights.fluentPut("蘋果", 3)
        .fluentPut("草莓", 3);
        root.put("WordWeights", wordWeights);

        System.out.println(root.toJSONString());
        request.setHttpContent(root.toJSONString().getBytes(), "utf-8", FormatType.JSON);

        // TODO 請通過環境變量設置您的AccessKeyId、AccessKeySecret
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        IAcsClient client = new DefaultAcsClient(profile);
        CommonResponse response = client.getCommonResponse(request);
        System.out.println(response.getData());
    }
  
    public static CommonRequest createCommonRequest(String domain, String version, ProtocolType protocolType, MethodType method, String uri) {
        // 創建API請求并設置參數
        CommonRequest request = new CommonRequest();
        request.setSysDomain(domain);
        request.setSysVersion(version);
        request.setSysProtocol(protocolType);
        request.setSysMethod(method);
        request.setSysUriPattern(uri);
        request.setHttpContentType(FormatType.JSON);
        return request;
    }
}

示例輸出

{
  "Code": "0",
  "Data": {
    "PhraseId": "4424074c1d02421bb88849c3fa11****",
    "Status": "SUCCEEDED"
  },
  "Message": "success",
  "RequestId": "30CAC8F3-903C-5F30-BD37-120B413E*****"
}

協議解析

具體字段定義如下。

參數名

類型

說明

PhraseId

string

熱詞的詞表Id,用于后續的詞表更新維護以及音視頻轉寫的效果增強。

Status

string

任務狀態

RequestId

string

RequestId用于排查問題使用。