Boost term recognition
Hotwords help the model recognize terms it might otherwise miss -- business terms, product names, or proper nouns.
Field descriptions:
Hotword text length rules:
Hotwords overview
Submit a JSON array of hotword objects. Example: Improve movie title recognition (Fun-ASR and Paraformer series models)Copy
[
{"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"}
]
| Field | Type | Required | Description |
|---|---|---|---|
| text | string | Yes | The hotword text. Must be supported by the selected model. Use actual words, not random characters. See length rules below. |
| weight | int | Yes | Priority weight, an integer from 1 to 5. Start with 4. Increase if results are weak, but too high a weight can hurt recognition of other words. |
| lang | string | No | Language code. Boosts hotwords for a specific language. Leave empty for auto-detection. See the model's API reference for supported codes. If you set language_hints, only matching hotwords take effect. |
-
Contains non-ASCII characters: Maximum 15 characters total, including non-ASCII characters (Chinese, Japanese kana, Korean Hangul, Russian Cyrillic) and ASCII characters.
Examples:
"厄洛替尼盐酸盐"(7 Chinese characters)"EGFR抑制剂"(3 Chinese characters and 4 ASCII characters, for a total of 7 characters)"こんにちは"(5 characters)"Фенибут Белфарм"(15 characters, including the space)"Клофелин Белмедпрепараты"(24 characters) -- exceeds limit
-
Contains only ASCII characters: Maximum 7 segments. A segment is a sequence of characters separated by spaces.
Examples:
"Exothermic reaction"-- 2 segments"Human immunodeficiency virus type 1"-- 5 segments"The effect of temperature variations on enzyme activity in biochemical reactions"-- 11 segments, exceeds limit
Supported models
Fun-ASR:- Real-time speech recognition: fun-asr-realtime, fun-asr-realtime-2025-11-07
- Audio file recognition: fun-asr, fun-asr-2025-11-07, fun-asr-2025-08-25, fun-asr-mtl, fun-asr-mtl-2025-08-25
Billing
Hotwords are free.Hotword quantity limits
- Each account can create up to 10 hotword lists, shared across all models. To increase this limit, submit a request.
- Each hotword list can have up to 500 words.
Getting started
Workflow
-
Create a hotword list by calling the Create API. Set
target_model(ortargetModelin Java) to the speech recognition model you plan to use. If you already have a list, skip this step and call Query all to view it. -
Pass the hotword list ID to the speech recognition API. The model must match the
target_model(ortargetModelin Java) from step 1.
Prerequisites
- Get an API key: Get your API key and export it as an environment variable.
- Install the SDK: Install the DashScope SDK.
Code examples
Audio file used in the examples: asr_example.wav.- Python
- Java
Copy
import dashscope
from dashscope.audio.asr import *
import os
# If you have not configured an environment variable, replace the following line with your API key: dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
dashscope.base_websocket_api_url='wss://dashscope-intl.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)
Copy
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 {
// If you have not configured an environment variable, replace the following line with your API key: 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-intl.aliyuncs.com/api/v1";
Constants.baseWebsocketApiUrl = "wss://dashscope-intl.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();
// Create a 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 {
// Close the WebSocket connection after the task is complete.
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 reference
Use the same account for all operations.Create a hotword list
For the hotword list JSON format, see Hotwords overview.- Python SDK
- Java SDK
- RESTful API
API descriptionCode example
target_model must match the model used in your speech recognition calls.Copy
def create_vocabulary(self, target_model: str, prefix: str, vocabulary: List[dict]) -> str:
'''
Create a hotword list.
param: target_model The speech recognition model (must match your recognition calls).
param: prefix Custom prefix (<10 lowercase letters/digits).
param: vocabulary The hotword list.
return: The hotword list ID.
'''
Copy
import dashscope
from dashscope.audio.asr import *
import os
# If you have not configured an environment variable, replace the following line with your API key: dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
prefix = 'testpfx'
target_model = "fun-asr"
my_vocabulary = [
{"text": "Seediq Bale", "weight": 4}
]
# Create a hotword
service = VocabularyService()
vocabulary_id = service.create_vocabulary(
prefix=prefix,
target_model=target_model,
vocabulary=my_vocabulary)
print(f"The hotword list ID is: {vocabulary_id}")
API descriptionCode example
targetModel must match the model used in your speech recognition calls.Copy
/**
* Create a hotword list.
*
* @param targetModel The speech recognition model (must match your recognition calls).
* @param prefix Custom prefix (<10 lowercase letters/digits).
* @param vocabulary The hotword list.
* @return The hotword list object.
* @throws NoApiKeyException if the API key is empty.
* @throws InputRequiredException if a required parameter is empty.
*/
public Vocabulary createVocabulary(String targetModel, String prefix, JsonArray vocabulary)
throws NoApiKeyException, InputRequiredException
Copy
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 {
// If you have not configured an environment variable, replace the following line with your API key: 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-intl.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("Hotword list ID: " + vocabulary.getVocabularyId());
}
}
class Hotword {
String text;
int weight;
String lang;
public Hotword(String text, int weight) {
this.text = text;
this.weight = weight;
}
}
URLRequest headers
Request body
Request body exampleResponse body
Response body examplecurl example
Copy
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customization
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer $DASHSCOPE_API_KEY. |
| Content-Type | string | Yes | application/json. |
target_model must match the model used in your speech recognition calls.| Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
| model | string | - | Yes | Set to speech-biasing. |
| action | string | - | Yes | Set to create_vocabulary. |
| target_model | string | - | Yes | The speech recognition model for this hotword list. Must match the model in your recognition calls. See Supported models. |
| prefix | string | - | Yes | A name for the hotword list (<10 lowercase letters/digits). Appears in the hotword list ID. Example: prefix "testpfx" produces ID "vocab-testpfx-51773d05xxxxxx". |
| vocabulary | array[object] | - | Yes | The hotword list. See Hotwords overview. |
Copy
{
"model": "speech-biasing",
"input": {
"action": "create_vocabulary",
"target_model": "fun-asr",
"prefix": "testpfx",
"vocabulary": [
{"text": "Seediq Bale", "weight": 4, "lang": "zh"}
]
}
}
| Parameter | Type | Description |
|---|---|---|
| vocabulary_id | string | The hotword list ID. |
Copy
{
"output": {
"vocabulary_id": "vocab-testpfx-5112c3de3705486baxxxxxxx"
},
"usage": {
"count": 1
},
"request_id": "aee47022-2352-40fe-acfa-xxxx"
}
Copy
curl -X POST https://dashscope-intl.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}
]
}
}'
Query all hotword lists
- Python SDK
- Java SDK
- RESTful API
API descriptionCode exampleResponse example
Copy
def list_vocabularies(self, prefix=None, page_index: int = 0, page_size: int = 10) -> List[dict]:
'''
List all hotword lists.
param: prefix Filter by prefix. Returns only matching lists.
param: page_index Page index.
param: page_size Page size.
return: A list of hotword list identifiers.
'''
Copy
import dashscope
from dashscope.audio.asr import *
import json
import os
# If you have not configured an environment variable, replace the following line with your API key: dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
service = VocabularyService()
vocabularies = service.list_vocabularies()
print(f"Hotword list: {json.dumps(vocabularies)}")
Copy
[
{
"gmt_create": "2025-04-22 14:23:35",
"vocabulary_id": "vocab-testpfx-5112c3de3705486baxxxxxxx",
"gmt_modified": "2025-04-22 14:23:35",
"status": "OK"
}
]
API descriptionCode exampleResponse example
Copy
/**
* List all hotword lists. Defaults: page index 0, page size 10.
*
* @param prefix Filter by prefix.
* @return An array of hotword list objects.
* @throws NoApiKeyException if the API key is empty.
* @throws InputRequiredException if a required parameter is empty.
*/
public Vocabulary[] listVocabulary(String prefix)
throws NoApiKeyException, InputRequiredException
/**
* List all hotword lists.
*
* @param prefix Filter by prefix.
* @param pageIndex Page index.
* @param pageSize Page size.
* @return An array of hotword list objects.
* @throws NoApiKeyException if the API key is empty.
* @throws InputRequiredException if a required parameter is empty.
*/
public Vocabulary[] listVocabulary(String prefix, int pageIndex, int pageSize)
throws NoApiKeyException, InputRequiredException
Copy
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 {
// If you have not configured an environment variable, replace the following line with your API key: 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-intl.aliyuncs.com/api/v1";
VocabularyService service = new VocabularyService(apiKey);
Vocabulary[] vocabularies = service.listVocabulary("testpfx");
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.create();
System.out.println("Hotword list: " + gson.toJson(vocabularies));
}
}
Copy
[
{
"gmt_create": "2025-04-22 14:23:35",
"vocabulary_id": "vocab-testpfx-5112c3de3705486baxxxxxxx",
"gmt_modified": "2025-04-22 14:23:35",
"status": "OK"
}
]
URLRequest headers
Request body
Request body exampleResponse body
Response body examplecurl example
Copy
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customization
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer $DASHSCOPE_API_KEY. |
| Content-Type | string | Yes | application/json. |
model: Set to speech-biasing.| Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
| model | string | - | Yes | Set to speech-biasing. |
| action | string | - | Yes | Set to list_vocabulary. |
| prefix | string | - | No | Filter by prefix (<10 lowercase letters/digits). |
| page_index | integer | 0 | No | Page number, starting from 0. |
| page_size | integer | 10 | No | Entries per page. |
Copy
{
"model": "speech-biasing",
"input": {
"action": "list_vocabulary",
"prefix": "testpfx",
"page_index": 0,
"page_size": 10
}
}
| Parameter | Type | Description |
|---|---|---|
| vocabulary_id | string | The hotword list ID. |
| gmt_create | string | Creation time. |
| gmt_modified | string | Last modified time. |
| status | string | Status: OK (ready) or UNDEPLOYED (not ready). |
Copy
{
"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"
}
Copy
curl -X POST https://dashscope-intl.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
}
}'
Query a specific hotword list
- Python SDK
- Java SDK
- RESTful API
API descriptionCode exampleResponse example
Copy
def query_vocabulary(self, vocabulary_id: str) -> List[dict]:
'''
Get a hotword list by ID.
param: vocabulary_id The hotword list ID.
return: The hotword list.
'''
Copy
import dashscope
from dashscope.audio.asr import *
import json
import os
# If you have not configured an environment variable, replace the following line with your API key: dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
service = VocabularyService()
# Replace with your actual hotword list ID when querying.
vocabulary = service.query_vocabulary("vocab-testpfx-xxx")
print(f"Hotword list: {json.dumps(vocabulary, ensure_ascii=False)}")
Copy
{
"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
}
]
}
API descriptionCode exampleResponse example
Copy
/**
* Query a specific hotword list.
*
* @param vocabularyId The hotword list ID.
* @return The hotword list object.
* @throws NoApiKeyException if the API key is empty.
* @throws InputRequiredException if a required parameter is empty.
*/
public Vocabulary queryVocabulary(String vocabularyId)
throws NoApiKeyException, InputRequiredException
Copy
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 {
// If you have not configured an environment variable, replace the following line with your API key: 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-intl.aliyuncs.com/api/v1";
VocabularyService service = new VocabularyService(apiKey);
// Replace with your actual hotword list ID when querying.
Vocabulary vocabulary = service.queryVocabulary("vocab-testpfx-xxxx");
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.create();
System.out.println("Hotword list: " + gson.toJson(vocabulary.getData()));
}
}
Copy
{
"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
}
]
}
URLRequest headers
Request body
Request body exampleResponse body
Response body examplecurl example
Copy
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customization
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer $DASHSCOPE_API_KEY. |
| Content-Type | string | Yes | application/json. |
model: Set to speech-biasing.| Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
| model | string | - | Yes | Set to speech-biasing. |
| action | string | - | Yes | Set to query_vocabulary. |
| vocabulary_id | string | - | Yes | The hotword list ID to query. |
Copy
{
"model": "speech-biasing",
"input": {
"action": "query_vocabulary",
"vocabulary_id": "vocab-testpfx-xxxx"
}
}
| Parameter | Type | Description |
|---|---|---|
| vocabulary | object[] | The hotword list. See Hotwords overview. |
| gmt_create | string | Creation time. |
| gmt_modified | string | Last modified time. |
| target_model | string | The speech recognition model for this hotword list. See Supported models. |
| status | string | Status: OK (ready) or UNDEPLOYED (not ready). |
Copy
{
"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"
}
Copy
curl -X POST https://dashscope-intl.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"
}
}'
Update a hotword list
- Python SDK
- Java SDK
- RESTful API
API descriptionCode example
Copy
def update_vocabulary(self, vocabulary_id: str, vocabulary: List[dict]) -> None:
'''
Replace a hotword list.
param: vocabulary_id The hotword list ID to replace.
param: vocabulary The new hotword list.
'''
Copy
import dashscope
from dashscope.audio.asr import *
import os
# If you have not configured an environment variable, replace the following line with your API key: dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
service = VocabularyService()
my_vocabulary = [
{"text": "Seediq Bale", "weight": 4, "lang": "zh"}
]
# Replace with your actual hotword list ID.
service.update_vocabulary("vocab-testpfx-xxx", my_vocabulary)
API descriptionCode example
Copy
/**
* Update a hotword list.
*
* @param vocabularyId The hotword list ID to update.
* @param vocabulary The new hotword list.
* @throws NoApiKeyException if the API key is empty.
* @throws InputRequiredException if a required parameter is empty.
*/
public void updateVocabulary(String vocabularyId, JsonArray vocabulary)
throws NoApiKeyException, InputRequiredException
Copy
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 {
// If you have not configured an environment variable, replace the following line with your API key: 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-intl.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);
// Replace with your actual hotword list 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;
}
}
URLRequest headers
Request body
Request body exampleResponse body examplecurl example
Copy
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customization
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer $DASHSCOPE_API_KEY. |
| Content-Type | string | Yes | application/json. |
model: Set to speech-biasing.| Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
| model | string | - | Yes | Set to speech-biasing. |
| action | string | - | Yes | Set to update_vocabulary. |
| vocabulary_id | string | - | Yes | The hotword list ID to update. |
| vocabulary | object[] | - | Yes | The new hotword list. See Hotwords overview. |
Copy
{
"model": "speech-biasing",
"input": {
"action": "update_vocabulary",
"vocabulary_id": "vocab-testpfx-6977ae49f65c4c3db054727cxxxxxxxx",
"vocabulary": [
{"text": "Seediq Bale", "weight": 4, "lang": "zh"}
]
}
}
Copy
{
"output": {},
"usage": {
"count": 1
},
"request_id": "aee47022-2352-40fe-acfa-xxxx"
}
Copy
curl -X POST https://dashscope-intl.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"}
]
}
}'
Delete a hotword list
- Python SDK
- Java SDK
- RESTful API
API descriptionCode example
Copy
def delete_vocabulary(self, vocabulary_id: str) -> None:
'''
Delete a hotword list.
param: vocabulary_id The hotword list ID to delete.
'''
Copy
import dashscope
from dashscope.audio.asr import *
import os
# If you have not configured an environment variable, replace the following line with your API key: dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
service = VocabularyService()
# Replace with your actual hotword list ID.
service.delete_vocabulary("vocab-testpfx-xxxx")
API descriptionCode example
Copy
/**
* Delete a hotword list.
*
* @param vocabularyId The hotword list ID to delete.
* @throws NoApiKeyException if the API key is empty.
* @throws InputRequiredException if a required parameter is empty.
*/
public void deleteVocabulary(String vocabularyId)
throws NoApiKeyException, InputRequiredException
Copy
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 {
// If you have not configured an environment variable, replace the following line with your API key: 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-intl.aliyuncs.com/api/v1";
VocabularyService service = new VocabularyService(apiKey);
// Replace with your actual hotword list ID when deleting.
service.deleteVocabulary("vocab-testpfx-xxxx");
}
}
URLRequest headers
Request body
Request body exampleResponse body examplecurl example
Copy
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customization
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer $DASHSCOPE_API_KEY. |
| Content-Type | string | Yes | application/json. |
model: Set to speech-biasing.| Parameter | Type | Default | Required | Description |
|---|---|---|---|---|
| model | string | - | Yes | Set to speech-biasing. |
| action | string | - | Yes | Set to delete_vocabulary. |
| vocabulary_id | string | - | Yes | The hotword list ID to delete. |
Copy
{
"model": "speech-biasing",
"input": {
"action": "delete_vocabulary",
"vocabulary_id": "vocab-testpfx-xxx"
}
}
Copy
{
"output": {},
"usage": {
"count": 1
},
"request_id": "aee47022-2352-40fe-acfa-xxxx"
}
Copy
curl -X POST https://dashscope-intl.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"
}
}'