提升专有名词的识别准确率
热词帮助模型准确识别容易漏识或误识的术语,如业务术语、产品名称或人名地名等专有名词。
字段说明:
热词文本长度规则:
热词概述
以 JSON 数组格式提交热词对象列表。 示例:提升电影名称的识别准确率(Fun-ASR 和 Paraformer 系列模型)复制
[
{"text": "赛德克巴莱", "weight": 4, "lang": "zh"},
{"text": "Seediq Bale", "weight": 4, "lang": "en"},
{"text": "夏洛特烦恼", "weight": 4, "lang": "zh"},
{"text": "Goodbye Mr. Loser", "weight": 4, "lang": "en"},
{"text": "阙里人家", "weight": 4, "lang": "zh"},
{"text": "Confucius' Family", "weight": 4, "lang": "en"}
]
| 字段 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| text | string | 是 | 热词文本。必须是所选模型支持的词语,不能使用随机字符。长度规则见下文。 |
| weight | int | 是 | 优先级权重,取值范围为 1~5 的整数。建议从 4 开始调整。效果不佳时可适当调高,但权重过高可能影响其他词的识别。 |
| lang | string | 否 | 语言代码。指定后仅对该语言的热词生效。留空则自动检测语言。支持的语言代码请参考对应模型的 API 参考文档。如果设置了 language_hints,仅匹配的热词会生效。 |
-
包含非 ASCII 字符:总长度不超过 15 个字符,包括非 ASCII 字符(中文、日文假名、韩文、俄文西里尔字母)和 ASCII 字符。
示例:
"厄洛替尼盐酸盐"(7 个中文字符)"EGFR抑制剂"(3 个中文字符和 4 个 ASCII 字符,共 7 个字符)"こんにちは"(5 个字符)"Фенибут Белфарм"(15 个字符,含空格)"Клофелин Белмедпрепараты"(24 个字符)——超出限制
-
仅包含 ASCII 字符:不超过 7 个词段。词段是以空格分隔的字符序列。
示例:
"Exothermic reaction"—— 2 个词段"Human immunodeficiency virus type 1"—— 5 个词段"The effect of temperature variations on enzyme activity in biochemical reactions"—— 11 个词段,超出限制
支持的模型
所有 Fun-ASR 模型均支持热词功能。完整模型列表请参见语音转文字模型。计费
热词功能免费使用。热词数量限制
- 每个账号最多创建 10 个热词表,所有模型共享。如需提升配额,请提交工单。
- 每个热词表最多包含 500 个词。
快速开始
使用流程
-
创建热词表:调用创建热词表 API。将
target_model(Java 中为targetModel)设置为您要使用的语音识别模型。如果已有热词表,可跳过此步骤,调用查询所有热词表查看。 -
传入热词表 ID:将热词表 ID 传给语音识别 API。使用的模型必须与步骤 1 中的
target_model(Java 中为targetModel)一致。
前提条件
- 获取 API Key:获取 API Key 并将其配置为环境变量。
- 安装 SDK:安装 DashScope SDK。
代码示例
示例中使用的音频文件:asr_example.wav。- Python
- Java
复制
import dashscope
from dashscope.audio.asr import *
import os
# 如果未配置环境变量,请将下一行替换为:dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
dashscope.base_websocket_api_url='wss://dashscope.aliyuncs.com/api-ws/v1/inference'
prefix = 'testpfx'
target_model = "fun-asr-realtime"
my_vocabulary = [
{"text": "Speech Lab", "weight": 4}
]
service = VocabularyService()
vocabulary_id = service.create_vocabulary(
prefix=prefix,
target_model=target_model,
vocabulary=my_vocabulary)
if service.query_vocabulary(vocabulary_id)['status'] == 'OK':
recognition = Recognition(model=target_model,
format='wav',
sample_rate=16000,
callback=None,
vocabulary_id=vocabulary_id)
result = recognition.call('asr_example.wav')
print(result.output)
service.delete_vocabulary(vocabulary_id)
复制
import com.alibaba.dashscope.audio.asr.recognition.Recognition;
import com.alibaba.dashscope.audio.asr.recognition.RecognitionParam;
import com.alibaba.dashscope.audio.asr.vocabulary.Vocabulary;
import com.alibaba.dashscope.audio.asr.vocabulary.VocabularyService;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class Main {
// 如果未配置环境变量,请将下一行替换为:public static String apiKey = "sk-xxx"
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void main(String[] args) throws NoApiKeyException, InputRequiredException {
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
Constants.baseWebsocketApiUrl = "wss://dashscope.aliyuncs.com/api-ws/v1/inference";
String targetModel = "fun-asr-realtime";
JsonArray vocabularyJson = new JsonArray();
List<Hotword> wordList = new ArrayList<>();
wordList.add(new Hotword("Speech Lab", 4));
for (Hotword word : wordList) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("text", word.text);
jsonObject.addProperty("weight", word.weight);
vocabularyJson.add(jsonObject);
}
VocabularyService service = new VocabularyService(apiKey);
Vocabulary vocabulary = service.createVocabulary(targetModel, "testpfx", vocabularyJson);
if ("OK".equals(service.queryVocabulary(vocabulary.getVocabularyId()).getStatus())) {
Recognition recognizer = new Recognition();
// 创建 RecognitionParam
RecognitionParam param =
RecognitionParam.builder()
.model(targetModel)
.apiKey(apiKey)
.format("wav")
.sampleRate(16000)
.build();
try {
System.out.println("Recognition result: " + recognizer.call(param, new File("asr_example.wav")));
} catch (Exception e) {
e.printStackTrace();
} finally {
// 任务完成后关闭 WebSocket 连接
recognizer.getDuplexApi().close(1000, "bye");
}
}
service.deleteVocabulary(vocabulary.getVocabularyId());
System.exit(0);
}
}
class Hotword {
String text;
int weight;
public Hotword(String text, int weight) {
this.text = text;
this.weight = weight;
}
}
API 参考
所有操作请使用同一账号。创建热词表
热词表的 JSON 格式请参见热词概述。- Python SDK
- Java SDK
- RESTful API
接口说明代码示例
target_model 必须与语音识别调用中使用的模型一致。复制
def create_vocabulary(self, target_model: str, prefix: str, vocabulary: List[dict]) -> str:
'''
创建热词表。
param: target_model 语音识别模型(必须与识别调用中使用的模型一致)。
param: prefix 自定义前缀(不超过 10 个小写字母或数字)。
param: vocabulary 热词列表。
return: 热词表 ID。
'''
复制
import dashscope
from dashscope.audio.asr import *
import os
# 如果未配置环境变量,请将下一行替换为:dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
prefix = 'testpfx'
target_model = "fun-asr"
my_vocabulary = [
{"text": "Seediq Bale", "weight": 4}
]
# 创建热词表
service = VocabularyService()
vocabulary_id = service.create_vocabulary(
prefix=prefix,
target_model=target_model,
vocabulary=my_vocabulary)
print(f"热词表 ID:{vocabulary_id}")
接口说明代码示例
targetModel 必须与语音识别调用中使用的模型一致。复制
/**
* 创建热词表。
*
* @param targetModel 语音识别模型(必须与识别调用中使用的模型一致)。
* @param prefix 自定义前缀(不超过 10 个小写字母或数字)。
* @param vocabulary 热词列表。
* @return 热词表对象。
* @throws NoApiKeyException API Key 为空时抛出。
* @throws InputRequiredException 必填参数为空时抛出。
*/
public Vocabulary createVocabulary(String targetModel, String prefix, JsonArray vocabulary)
throws NoApiKeyException, InputRequiredException
复制
import com.alibaba.dashscope.audio.asr.vocabulary.Vocabulary;
import com.alibaba.dashscope.audio.asr.vocabulary.VocabularyService;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.List;
public class Main {
// 如果未配置环境变量,请将下一行替换为:public static String apiKey = "sk-xxx"
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void main(String[] args) throws NoApiKeyException, InputRequiredException {
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
String targetModel = "fun-asr";
JsonArray vocabularyJson = new JsonArray();
List<Hotword> wordList = new ArrayList<>();
wordList.add(new Hotword("Wu Yigong", 4));
wordList.add(new Hotword("Queli Renjia", 4));
for (Hotword word : wordList) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("text", word.text);
jsonObject.addProperty("weight", word.weight);
vocabularyJson.add(jsonObject);
}
VocabularyService service = new VocabularyService(apiKey);
Vocabulary vocabulary = service.createVocabulary(targetModel, "testpfx", vocabularyJson);
System.out.println("热词表 ID:" + vocabulary.getVocabularyId());
}
}
class Hotword {
String text;
int weight;
String lang;
public Hotword(String text, int weight) {
this.text = text;
this.weight = weight;
}
}
请求 URL请求头
请求体响应体
响应体示例curl 示例
复制
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer $DASHSCOPE_API_KEY。 |
| Content-Type | string | 是 | application/json。 |
target_model 必须与语音识别调用中使用的模型一致。请求体示例
复制
{
"model": "speech-biasing",
"input": {
"action": "create_vocabulary",
"target_model": "fun-asr",
"prefix": "testpfx",
"vocabulary": [
{"text": "Seediq Bale", "weight": 4, "lang": "zh"}
]
}
}
| 参数 | 类型 | 说明 |
|---|---|---|
| vocabulary_id | string | 热词表 ID。 |
复制
{
"output": {
"vocabulary_id": "vocab-testpfx-5112c3de3705486baxxxxxxx"
},
"usage": {
"count": 1
},
"request_id": "aee47022-2352-40fe-acfa-xxxx"
}
复制
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "speech-biasing",
"input": {
"action": "create_vocabulary",
"target_model": "fun-asr",
"prefix": "testpfx",
"vocabulary": [
{"text": "Seediq Bale", "weight": 4}
]
}
}'
查询所有热词表
- Python SDK
- Java SDK
- RESTful API
接口说明代码示例响应示例
复制
def list_vocabularies(self, prefix=None, page_index: int = 0, page_size: int = 10) -> List[dict]:
'''
查询所有热词表。
param: prefix 按前缀筛选,仅返回匹配的热词表。
param: page_index 页码。
param: page_size 每页条数。
return: 热词表标识列表。
'''
复制
import dashscope
from dashscope.audio.asr import *
import json
import os
# 如果未配置环境变量,请将下一行替换为:dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
service = VocabularyService()
vocabularies = service.list_vocabularies()
print(f"热词表列表:{json.dumps(vocabularies)}")
复制
[
{
"gmt_create": "2025-04-22 14:23:35",
"vocabulary_id": "vocab-testpfx-5112c3de3705486baxxxxxxx",
"gmt_modified": "2025-04-22 14:23:35",
"status": "OK"
}
]
接口说明代码示例响应示例
复制
/**
* 查询所有热词表。默认:页码 0,每页 10 条。
*
* @param prefix 按前缀筛选。
* @return 热词表对象数组。
* @throws NoApiKeyException API Key 为空时抛出。
* @throws InputRequiredException 必填参数为空时抛出。
*/
public Vocabulary[] listVocabulary(String prefix)
throws NoApiKeyException, InputRequiredException
/**
* 查询所有热词表。
*
* @param prefix 按前缀筛选。
* @param pageIndex 页码。
* @param pageSize 每页条数。
* @return 热词表对象数组。
* @throws NoApiKeyException API Key 为空时抛出。
* @throws InputRequiredException 必填参数为空时抛出。
*/
public Vocabulary[] listVocabulary(String prefix, int pageIndex, int pageSize)
throws NoApiKeyException, InputRequiredException
复制
import com.alibaba.dashscope.audio.asr.vocabulary.Vocabulary;
import com.alibaba.dashscope.audio.asr.vocabulary.VocabularyService;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Main {
// 如果未配置环境变量,请将下一行替换为:public static String apiKey = "sk-xxx"
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void main(String[] args) throws NoApiKeyException, InputRequiredException {
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
VocabularyService service = new VocabularyService(apiKey);
Vocabulary[] vocabularies = service.listVocabulary("testpfx");
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.create();
System.out.println("热词表列表:" + gson.toJson(vocabularies));
}
}
复制
[
{
"gmt_create": "2025-04-22 14:23:35",
"vocabulary_id": "vocab-testpfx-5112c3de3705486baxxxxxxx",
"gmt_modified": "2025-04-22 14:23:35",
"status": "OK"
}
]
请求 URL请求头
请求体
请求体示例响应体
响应体示例curl 示例
复制
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer $DASHSCOPE_API_KEY。 |
| Content-Type | string | 是 | application/json。 |
model:固定为 speech-biasing。| 参数 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| model | string | - | 是 | 固定为 speech-biasing。 |
| action | string | - | 是 | 固定为 list_vocabulary。 |
| prefix | string | - | 否 | 按前缀筛选(不超过 10 个小写字母或数字)。 |
| page_index | integer | 0 | 否 | 页码,从 0 开始。 |
| page_size | integer | 10 | 否 | 每页条数。 |
复制
{
"model": "speech-biasing",
"input": {
"action": "list_vocabulary",
"prefix": "testpfx",
"page_index": 0,
"page_size": 10
}
}
| 参数 | 类型 | 说明 |
|---|---|---|
| vocabulary_id | string | 热词表 ID。 |
| gmt_create | string | 创建时间。 |
| gmt_modified | string | 最后修改时间。 |
| status | string | 状态:OK(就绪)或 UNDEPLOYED(未就绪)。 |
复制
{
"output": {
"vocabulary_list": [
{
"gmt_create": "2025-12-19 11:47:11",
"gmt_modified": "2025-12-19 11:47:11",
"status": "OK",
"vocabulary_id": "vocab-testpfx-xxxxxxxx"
}
]
},
"usage": {
"count": 1
},
"request_id": "10e8cde2-b711-4609-b19b-xxxxxx"
}
复制
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "speech-biasing",
"input": {
"action": "list_vocabulary",
"prefix": "testpfx",
"page_index": 0,
"page_size": 10
}
}'
查询指定热词表
- Python SDK
- Java SDK
- RESTful API
接口说明代码示例响应示例
复制
def query_vocabulary(self, vocabulary_id: str) -> List[dict]:
'''
根据 ID 查询热词表。
param: vocabulary_id 热词表 ID。
return: 热词表内容。
'''
复制
import dashscope
from dashscope.audio.asr import *
import json
import os
# 如果未配置环境变量,请将下一行替换为:dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
service = VocabularyService()
# 查询时请替换为实际的热词表 ID
vocabulary = service.query_vocabulary("vocab-testpfx-xxx")
print(f"热词表内容:{json.dumps(vocabulary, ensure_ascii=False)}")
复制
{
"gmt_create": "2025-12-19 11:47:11",
"gmt_modified": "2025-12-19 11:47:11",
"status": "OK",
"target_model": "fun-asr",
"vocabulary": [
{
"lang": "zh",
"text": "Seediq Bale",
"weight": 4
}
]
}
接口说明代码示例响应示例
复制
/**
* 查询指定热词表。
*
* @param vocabularyId 热词表 ID。
* @return 热词表对象。
* @throws NoApiKeyException API Key 为空时抛出。
* @throws InputRequiredException 必填参数为空时抛出。
*/
public Vocabulary queryVocabulary(String vocabularyId)
throws NoApiKeyException, InputRequiredException
复制
import com.alibaba.dashscope.audio.asr.vocabulary.Vocabulary;
import com.alibaba.dashscope.audio.asr.vocabulary.VocabularyService;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Main {
// 如果未配置环境变量,请将下一行替换为:public static String apiKey = "sk-xxx"
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void main(String[] args) throws NoApiKeyException, InputRequiredException {
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
VocabularyService service = new VocabularyService(apiKey);
// 查询时请替换为实际的热词表 ID
Vocabulary vocabulary = service.queryVocabulary("vocab-testpfx-xxxx");
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.create();
System.out.println("热词表内容:" + gson.toJson(vocabulary.getData()));
}
}
复制
{
"gmt_create": "2025-12-19 11:47:11",
"gmt_modified": "2025-12-19 11:47:11",
"status": "OK",
"target_model": "fun-asr",
"vocabulary": [
{
"lang": "zh",
"text": "Seediq Bale",
"weight": 4
}
]
}
请求 URL请求头
请求体
请求体示例响应体curl 示例
复制
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer $DASHSCOPE_API_KEY。 |
| Content-Type | string | 是 | application/json。 |
model:固定为 speech-biasing。| 参数 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| model | string | - | 是 | 固定为 speech-biasing。 |
| action | string | - | 是 | 固定为 query_vocabulary。 |
| vocabulary_id | string | - | 是 | 要查询的热词表 ID。 |
复制
{
"model": "speech-biasing",
"input": {
"action": "query_vocabulary",
"vocabulary_id": "vocab-testpfx-xxxx"
}
}
响应体示例
复制
{
"output": {
"gmt_create": "2025-12-19 11:47:11",
"gmt_modified": "2025-12-19 11:47:11",
"status": "OK",
"target_model": "fun-asr",
"vocabulary": [
{
"lang": "zh",
"text": "Seediq Bale",
"weight": 4
}
]
},
"usage": {
"count": 1
},
"request_id": "3d461d3f-b2c4-4de5-xxxx"
}
复制
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "speech-biasing",
"input": {
"action": "query_vocabulary",
"vocabulary_id": "vocab-testpfx-xxxx"
}
}'
更新热词表
- Python SDK
- Java SDK
- RESTful API
接口说明代码示例
复制
def update_vocabulary(self, vocabulary_id: str, vocabulary: List[dict]) -> None:
'''
替换热词表内容。
param: vocabulary_id 要替换的热词表 ID。
param: vocabulary 新的热词列表。
'''
复制
import dashscope
from dashscope.audio.asr import *
import os
# 如果未配置环境变量,请将下一行替换为:dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
service = VocabularyService()
my_vocabulary = [
{"text": "Seediq Bale", "weight": 4, "lang": "zh"}
]
# 请替换为实际的热词表 ID
service.update_vocabulary("vocab-testpfx-xxx", my_vocabulary)
接口说明代码示例
复制
/**
* 更新热词表。
*
* @param vocabularyId 要更新的热词表 ID。
* @param vocabulary 新的热词列表。
* @throws NoApiKeyException API Key 为空时抛出。
* @throws InputRequiredException 必填参数为空时抛出。
*/
public void updateVocabulary(String vocabularyId, JsonArray vocabulary)
throws NoApiKeyException, InputRequiredException
复制
import com.alibaba.dashscope.audio.asr.vocabulary.VocabularyService;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.ArrayList;
import java.util.List;
public class Main {
// 如果未配置环境变量,请将下一行替换为:public static String apiKey = "sk-xxx"
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void main(String[] args) throws NoApiKeyException, InputRequiredException {
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
JsonArray vocabularyJson = new JsonArray();
List<Hotword> wordList = new ArrayList<>();
wordList.add(new Hotword("Wu Yigong", 4, "zh"));
wordList.add(new Hotword("Queli Renjia", 4, "zh"));
for (Hotword word : wordList) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("text", word.text);
jsonObject.addProperty("weight", word.weight);
jsonObject.addProperty("lang", word.lang);
vocabularyJson.add(jsonObject);
}
VocabularyService service = new VocabularyService(apiKey);
// 请替换为实际的热词表 ID
service.updateVocabulary("vocab-testpfx-xxx", vocabularyJson);
}
}
class Hotword {
String text;
int weight;
String lang;
public Hotword(String text, int weight, String lang) {
this.text = text;
this.weight = weight;
this.lang = lang;
}
}
请求 URL请求头
请求体
请求体示例响应体示例curl 示例
复制
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer $DASHSCOPE_API_KEY。 |
| Content-Type | string | 是 | application/json。 |
model:固定为 speech-biasing。| 参数 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| model | string | - | 是 | 固定为 speech-biasing。 |
| action | string | - | 是 | 固定为 update_vocabulary。 |
| vocabulary_id | string | - | 是 | 要更新的热词表 ID。 |
| vocabulary | object[] | - | 是 | 新的热词列表。格式参见热词概述。 |
复制
{
"model": "speech-biasing",
"input": {
"action": "update_vocabulary",
"vocabulary_id": "vocab-testpfx-6977ae49f65c4c3db054727cxxxxxxxx",
"vocabulary": [
{"text": "Seediq Bale", "weight": 4, "lang": "zh"}
]
}
}
复制
{
"output": {},
"usage": {
"count": 1
},
"request_id": "aee47022-2352-40fe-acfa-xxxx"
}
复制
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "speech-biasing",
"input": {
"action": "update_vocabulary",
"vocabulary_id": "vocab-testpfx-xxx",
"vocabulary": [
{"text": "Seediq Bale", "weight": 4, "lang": "zh"}
]
}
}'
删除热词表
- Python SDK
- Java SDK
- RESTful API
接口说明代码示例
复制
def delete_vocabulary(self, vocabulary_id: str) -> None:
'''
删除热词表。
param: vocabulary_id 要删除的热词表 ID。
'''
复制
import dashscope
from dashscope.audio.asr import *
import os
# 如果未配置环境变量,请将下一行替换为:dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'
service = VocabularyService()
# 请替换为实际的热词表 ID
service.delete_vocabulary("vocab-testpfx-xxxx")
接口说明代码示例
复制
/**
* 删除热词表。
*
* @param vocabularyId 要删除的热词表 ID。
* @throws NoApiKeyException API Key 为空时抛出。
* @throws InputRequiredException 必填参数为空时抛出。
*/
public void deleteVocabulary(String vocabularyId)
throws NoApiKeyException, InputRequiredException
复制
import com.alibaba.dashscope.audio.asr.vocabulary.VocabularyService;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
public class Main {
// 如果未配置环境变量,请将下一行替换为:public static String apiKey = "sk-xxx"
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void main(String[] args) throws NoApiKeyException, InputRequiredException {
Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";
VocabularyService service = new VocabularyService(apiKey);
// 删除时请替换为实际的热词表 ID
service.deleteVocabulary("vocab-testpfx-xxxx");
}
}
请求 URL请求头
请求体
请求体示例响应体示例curl 示例
复制
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer $DASHSCOPE_API_KEY。 |
| Content-Type | string | 是 | application/json。 |
model:固定为 speech-biasing。| 参数 | 类型 | 默认值 | 是否必填 | 说明 |
|---|---|---|---|---|
| model | string | - | 是 | 固定为 speech-biasing。 |
| action | string | - | 是 | 固定为 delete_vocabulary。 |
| vocabulary_id | string | - | 是 | 要删除的热词表 ID。 |
复制
{
"model": "speech-biasing",
"input": {
"action": "delete_vocabulary",
"vocabulary_id": "vocab-testpfx-xxx"
}
}
复制
{
"output": {},
"usage": {
"count": 1
},
"request_id": "aee47022-2352-40fe-acfa-xxxx"
}
复制
curl -X POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "speech-biasing",
"input": {
"action": "delete_vocabulary",
"vocabulary_id": "vocab-testpfx-xxx"
}
}'

