接口描述
文本语种检测服务目前支持140种语言的识别检测,可识别文本所属语言种类,返回最可靠的结果。广泛应用于通用文本、商务沟通、搜索、广告、游戏等场景语种识别任务。
接口说明
字段 | 类型 | 是否为必须项 | 说明 | 备注 |
---|
TextList | [String] | 是 | 待检测的文本列表 | 列表长度不超过16 |
字段 | 类型 | 说明 | 备注 |
---|
ResponseMetadata | ResponseMetadata | 通用字段 | 无 |
DetectedLanguageList | [DetectedLanguage] | Language:: String 检测结果Confidence:: Double 置信度
| 置信度范围为0-1;置信度越高,检测结果越可靠 |
- 样例
{
"TextList": [
"Hello world"
]
}
{
"DetectedLanguageList": [
{
"Language": "en",
"Confidence": 1
}
],
"ResponseMetadata": {
"RequestId": "202004092241580100140440770840151B",
"Action": "LangDetect",
"Version": "2020-06-01",
"Service": "translate",
"Region": "cn-north-1",
"Error": null
}
}
示例代码
依赖 volc-sdk-python
import json
from volcengine.ApiInfo import ApiInfo
from volcengine.Credentials import Credentials
from volcengine.ServiceInfo import ServiceInfo
from volcengine.base.Service import Service
k_access_key = '密钥管理中的 AccessKey ID' # https://console.volcengine.com/iam/keymanage/
k_secret_key = '密钥管理中的 AccessKey Secret'
k_timeout = 5 # second
k_service_info = \
ServiceInfo('open.volcengineapi.com',
{'Content-Type': 'application/json'},
Credentials(k_access_key, k_secret_key, 'translate', 'cn-north-1'),
5,
5)
k_query = {
'Action': 'LangDetect',
'Version': '2020-06-01'
}
k_api_info = {
'langdetect': ApiInfo('POST', '/', k_query, {}, {})
}
service = Service(k_service_info, k_api_info)
body = {
'TextList': ['Hello world', 'こんにちは世界'],
}
print(service.json('langdetect', {}, json.dumps(body)))
package main
import (
"fmt"
"net/http"
"net/url"
"time"
"github.com/volcengine/volc-sdk-golang/base"
)
const (
kAccessKey = "密钥管理中的 AccessKey ID" // https://console.volcengine.com/iam/keymanage/
kSecretKey = "密钥管理中的 AccessKey Secret"
kServiceVersion = "2020-06-01"
)
var (
ServiceInfo = &base.ServiceInfo{
Timeout: 5 * time.Second,
Host: "open.volcengineapi.com",
Header: http.Header{
"Accept": []string{"application/json"},
},
Credentials: base.Credentials{Region: base.RegionCnNorth1, Service: "translate"},
}
ApiInfoList = map[string]*base.ApiInfo{
"LangDetect": {
Method: http.MethodPost,
Path: "/",
Query: url.Values{
"Action": []string{"LangDetect"},
"Version": []string{kServiceVersion},
},
},
}
)
func newClient() *base.Client {
client := base.NewClient(ServiceInfo, ApiInfoList)
client.SetAccessKey(kAccessKey)
client.SetSecretKey(kSecretKey)
return client
}
func main() {
client := newClient()
resp, code, err := client.Json("LangDetect", nil, `{"TextList":["你好世界"]}`)
if err != nil {
panic(err)
}
fmt.Printf("%d %s\n", code, string(resp))
}