You can use the hotword feature in speech recognition tasks when specific business terms, such as product names or proper nouns, are not accurately recognized. Add these terms as hotwords to prioritize them and improve recognition accuracy.
Hotwords overview
The hotword feature lets you submit a list of terms in a JSON array to improve the recognition accuracy of specific words. Each object in the array defines a hotword and its properties.
Example: Improving the recognition accuracy of movie titles (for Fun-ASR and Paraformer series models)
[
{"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 descriptions:
Field | Type | Required | Description |
text | string | The hotword text. The language of the hotword text must be supported by the selected model. Different models support different languages. Hotwords are used to improve recognition or translation accuracy. Use actual words, not random character combinations. The length of the hotword text is limited by the following rules:
| |
weight | int | The weight of the hotword. A common value is 4. The value must be an integer from 1 to 5. If the effect is not significant, you can increase the weight. However, a high weight might cause negative effects, leading to inaccurate recognition of other words. | |
lang | string | The language code. This lets you boost hotwords for a specific language supported by the ASR model. If you cannot determine the language in advance, you can leave this field empty. The model will automatically detect the language. For more information about the supported languages and their codes, see the API reference for the model. When you call the speech recognition service, specify the same language. If you specify a language in `language_hints`, hotwords for other languages will not take effect. |
Supported models
International (Singapore)
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
China (Beijing)
Fun-ASR:
Real-time speech recognition: fun-asr-realtime, fun-asr-realtime-2025-11-07, fun-asr-realtime-2025-09-15
Audio file recognition: fun-asr, fun-asr-2025-11-07, fun-asr-2025-08-25, fun-asr-mtl, fun-asr-mtl-2025-08-25
Paraformer:
Real-time speech recognition: paraformer-realtime-v2, paraformer-realtime-8k-v2
Audio file recognition: paraformer-v2, paraformer-8k-v2
Billing
The hotword feature is free of charge.
Hotword quantity limits
Each account can create up to 10 hotword lists. This quota is shared across all models. To increase the limit, you can submit a request.
Each hotword list can have up to 500 words.
Getting started: Create and use a hotword
Workflow
Creating and using a hotword list for speech recognition are two separate but related steps. You must first create the list and then use it in a request:
Create a hotword list.
Call the Create API operation for hotword lists. In this step, you must specify
target_model(ortargetModelin Java) to specify the speech recognition model that will use the hotword list.If you already have a hotword list, skip this step. Call the Query all API operation to view your existing lists.
Use the hotword list for speech recognition.
Call the speech recognition API and pass the hotword list ID in the request. The speech recognition model specified in this step must be the same as the
target_model(ortargetModelin Java) that you specified when you created the hotword list.
Prerequisites
Create an API key: Create and configure an API key. For security purposes, export the API key as an environment variable.
Install the SDK: Make sure that you have installed the latest version of the DashScope SDK.
Code examples
The audio file used in the examples is asr_example.wav.
Python
import dashscope
from dashscope.audio.asr import *
import os
# API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
# If you have not configured an environment variable, replace the following line with your Model Studio API key: dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
# The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: wss://dashscope.aliyuncs.com/api-ws/v1/inference
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)Java
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 {
// API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key
// If you have not configured an environment variable, replace the following line with your Model Studio 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 {
// The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
// The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: wss://dashscope.aliyuncs.com/api-ws/v1/inference
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
When you call these APIs, make sure to use the same account for all operations.
Create a hotword list
For more information about the format of the hotword list JSON, see Hotwords overview.
Python SDK
API description
Importanttarget_model: The speech recognition model that will use the hotword list. This model must be the same as the one specified in subsequent speech recognition API calls.def create_vocabulary(self, target_model: str, prefix: str, vocabulary: List[dict]) -> str: ''' Create a hotword list. param: target_model The speech recognition model for the hotword list. This must be the same as the speech recognition model used in subsequent API calls. param: prefix A custom prefix for the hotword list. It must contain fewer than 10 lowercase letters and digits. param: vocabulary The hotword list JSON. return: The hotword list ID. '''Code example
import dashscope from dashscope.audio.asr import * import os # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # If you have not configured an environment variable, replace the following line with your Model Studio API key: dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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}")
Java SDK
API description
ImportanttargetModel: The speech recognition model that will use the hotword list. This model must be the same as the one specified in subsequent speech recognition API calls./** * Create a new hotword list. * * @param targetModel The speech recognition model for the hotword list. This must be the same as the speech recognition model used in subsequent API calls. * @param prefix A custom prefix for the hotword. It must contain fewer than 10 lowercase letters and digits. * @param vocabulary The hotword list JSON. * @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, InputRequiredExceptionCode example
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 { // API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key // If you have not configured an environment variable, replace the following line with your Model Studio 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 { // The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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; } }
RESTful API
URL
China (Beijing):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationSingapore (International):
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationRequest headers
Parameter
Type
Required
Description
Authorization
string
The authentication token. The format is
Bearer <your_api_key>. Replace<your_api_key>with your actual API key.Content-Type
string
The media type of the data transferred in the request body. Set the value to
application/json.Request body
The following request body includes all request parameters. You can omit optional fields as needed.
ImportantNote the difference between the following parameters:
model: The custom hotword model. Set the value tospeech-biasing.target_model: The speech recognition model that will use the hotword list. This model must be the same as the one specified in subsequent speech recognition API calls.
{ "model": "speech-biasing", "input": { "action": "create_vocabulary", "target_model": "fun-asr", "prefix": "testpfx", "vocabulary": [ {"text": "Seediq Bale", "weight": 4, "lang": "zh"} ] } }Request parameters
Parameter
Type
Default
Required
Description
model
string
-
The custom hotword model. Set the value to
speech-biasing.action
string
-
The operation type. Set the value to
create_vocabulary.target_model
string
-
The speech recognition model that uses the hotword list. For more information, see Supported models.
This must be the same as the speech recognition model used in subsequent API calls.
prefix
string
-
Specify an easy-to-identify name for the hotword list. It must contain fewer than 10 lowercase letters and digits.
This keyword appears in the hotword list ID. For example, if the keyword is "testpfx", the final hotword list ID is "vocab-testpfx-51773d05xxxxxx".
vocabulary
array[object]
-
The hotword list JSON. For more information, see Hotwords overview.
Response parameters
Note the following parameters:
Parameter
Type
Description
vocabulary_id
string
The hotword list ID.
Code example
The following is a cURL example. For Java and Python examples, see the corresponding SDKs.
If you have not configured your API key as an environment variable, replace
$DASHSCOPE_API_KEYwith your actual API key.https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customization# ======= Important ======= # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # === Delete this comment before execution === curl -X POST <a data-init-id="9f104f338c7kz" href="https://poc-dashscope.aliyuncs.com/api/v1/services/audio/tts/customization" id="35ebbc67890ds">https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customization</a> \ -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
API description
def list_vocabularies(self, prefix=None, page_index: int = 0, page_size: int = 10) -> List[dict]: ''' Query all created hotword lists. param: prefix A custom prefix. If specified, returns only the identifiers of hotword lists with this prefix. param: page_index The page index. param: page_size The page size. return: A list of hotword list identifiers. '''Code example
import dashscope from dashscope.audio.asr import * import json import os # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # If you have not configured an environment variable, replace the following line with your Model Studio API key: dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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)}")Response parameters
The key parameters are as follows:
Parameter
Type
Description
vocabulary_id
string
The hotword list ID.
gmt_create
string
The time when the hotword list was created.
gmt_modified
string
The time when the hotword list was modified.
status
string
The status:
OK: Can be called.
UNDEPLOYED: Cannot be called.
Java SDK
API description
/** * Query all created hotword lists. The default page index is 0, and the default page size is 10. * * @param prefix A custom prefix for the hotword. * @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 /** * Query all created hotword lists. * * @param prefix A custom prefix for the hotword. * @param pageIndex The page index. * @param pageSize The 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, InputRequiredExceptionCode example
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 { // API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key // If you have not configured an environment variable, replace the following line with your Model Studio 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 { // The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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)); } }The key parameters are as follows:
Parameter
Type
Description
vocabulary_id
string
The hotword list ID.
gmt_create
string
The time when the hotword list was created.
gmt_modified
string
The time when the hotword list was modified.
status
string
The status:
OK: Can be called.
UNDEPLOYED: Cannot be called.
RESTful API
URL
China (Beijing):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationSingapore (International):
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationRequest headers
Parameter
Type
Required
Description
Authorization
string
The authentication token. The format is
Bearer <your_api_key>. Replace<your_api_key>with your actual API key.Content-Type
string
The media type of the data transferred in the request body. Set the value to
application/json.Request body
The following request body includes all request parameters. You can omit optional fields as needed.
Importantmodel: The custom hotword model. Set the value tospeech-biasing.{ "model": "speech-biasing", "input": { "action": "list_vocabulary", "prefix": "testpfx", "page_index": 0, "page_size": 10 } }Request parameters
Parameter
Type
Default
Required
Description
model
string
-
The custom hotword model. Set the value to
speech-biasing.action
string
-
The operation type. Set the value to
list_vocabulary.prefix
string
-
A custom prefix for the hotword list. It must contain fewer than 10 lowercase letters and digits.
page_index
integer
0
The page number. The count starts from 0.
page_size
integer
10
The number of entries per page.
Response parameters
Note the following parameters:
Parameter
Type
Description
vocabulary_id
string
The hotword list ID.
gmt_create
string
The time when the hotword list was created.
gmt_modified
string
The time when the hotword list was modified.
status
string
The status:
OK: Can be called.
UNDEPLOYED: Cannot be called.
Code example
The following is a cURL example. For Java and Python examples, see the corresponding SDKs.
If you have not configured your API key as an environment variable, replace
$DASHSCOPE_API_KEYwith your actual API key.# ======= Important ======= # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # === Delete this comment before execution === 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
When you query a specific hotword list, the response does not include the hotword list ID because it is provided in the request.
Python SDK
API description
def query_vocabulary(self, vocabulary_id: str) -> List[dict]: ''' Get the content of a hotword list. param: vocabulary_id The hotword list identifier. return: The hotword list. '''Code example
import dashscope from dashscope.audio.asr import * import json import os # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # If you have not configured an environment variable, replace the following line with your Model Studio API key: dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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)}")Response parameters
Note the following parameters:
Parameter
Type
Description
vocabulary
object[]
A dictionary for the hotword list. For more information about the fields, see Hotwords overview.
gmt_create
string
The time when the hotword list was created.
gmt_modified
string
The time when the hotword list was modified.
target_model
string
The speech recognition model that uses the hotword list. For more information, see Supported models.
This must be the same as the speech recognition model used in subsequent API calls.
status
string
The status:
OK: Can be called.
UNDEPLOYED: Cannot be called.
Java SDK
API description
/** * Query a specific hotword list. * * @param vocabularyId The hotword list to query. * @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, InputRequiredExceptionCode example
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 { // API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key // If you have not configured an environment variable, replace the following line with your Model Studio 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 { // The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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())); } }Response parameters
The following are the key parameters:
Parameter
Type
Description
vocabulary
object[]
A dictionary for the hotword list. For more information about the fields, see Hotwords overview.
gmt_create
string
The time when the hotword list was created.
gmt_modified
string
The time when the hotword list was modified.
target_model
string
The speech recognition model that uses the hotword list. For more information, see Supported models.
This must be the same as the speech recognition model used in subsequent API calls.
status
string
The status:
OK: Can be called.
UNDEPLOYED: Cannot be called.
RESTful API
URL
China (Beijing):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationSingapore (International):
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationRequest headers
Parameter
Type
Required
Description
Authorization
string
The authentication token. The format is
Bearer <your_api_key>. Replace<your_api_key>with your actual API key.Content-Type
string
The media type of the data transferred in the request body. Set the value to
application/json.Request body
The following request body includes all request parameters. You can omit optional fields as needed.
Importantmodel: The custom hotword model. Set the value tospeech-biasing.{ "model": "speech-biasing", "input": { "action": "query_vocabulary", "vocabulary_id": "vocab-testpfx-xxxx" } }Request parameters
Parameter
Type
Default
Required
Description
model
string
-
The custom hotword model. Set the value to
speech-biasing.action
string
-
The operation type. Set the value to
query_vocabulary.vocabulary_id
string
-
The ID of the hotword list to query.
Response parameters
The parameters are as follows:
Parameter
Type
Description
vocabulary
object[]
A dictionary for the hotword list. For more information about the fields, see Hotwords overview.
gmt_create
string
The time when the hotword list was created.
gmt_modified
string
The time when the hotword list was modified.
target_model
string
The speech recognition model that uses the hotword list. For more information, see Supported models.
This must be the same as the speech recognition model used in subsequent API calls.
status
string
The status:
OK: Can be called.
UNDEPLOYED: Cannot be called.
Code example
The following is a cURL example. For Java and Python examples, see the corresponding SDKs.
If you have not configured your API key as an environment variable, replace
$DASHSCOPE_API_KEYwith your actual API key.# ======= Important ======= # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # === Delete this comment before execution === 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
API description
def update_vocabulary(self, vocabulary_id: str, vocabulary: List[dict]) -> None: ''' Replace an existing hotword list with a new one. param: vocabulary_id The identifier of the hotword list to replace. param: vocabulary The hotword list. '''Code example
import dashscope from dashscope.audio.asr import * import os # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # If you have not configured an environment variable, replace the following line with your Model Studio API key: dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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)
Java SDK
API description
/** * Update a hotword list. * * @param vocabularyId The hotword list to update. * @param vocabulary The hotword list object. * @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, InputRequiredExceptionCode example
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 { // API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key // If you have not configured an environment variable, replace the following line with your Model Studio 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 { // The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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; } }
RESTful API
URL
China (Beijing):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationSingapore (International):
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationRequest headers
Parameter
Type
Required
Description
Authorization
string
The authentication token. The format is
Bearer <your_api_key>. Replace<your_api_key>with your actual API key.Content-Type
string
The media type of the data transferred in the request body. Set the value to
application/json.Request body
The following request body includes all request parameters. You can omit optional fields as needed.
Importantmodel: The custom hotword model. Set the value tospeech-biasing.{ "model": "speech-biasing", "input": { "action": "update_vocabulary", "vocabulary_id": "vocab-testpfx-6977ae49f65c4c3db054727cxxxxxxxx", "vocabulary": [ {"text": "Seediq Bale", "weight": 4, "lang": "zh"} ] } }Request parameters
Parameter
Type
Default
Required
Description
model
string
-
The custom hotword model. Set the value to
speech-biasing.action
string
-
The operation type. Set the value to
update_vocabulary.vocabulary_id
string
-
The ID of the hotword list to update.
vocabulary
object[]
-
A dictionary for the updated hotword list. For more information about the fields, see Hotwords overview.
Response parameters
Code example
The following is a cURL example. For Java and Python examples, see the corresponding SDKs.
If you have not configured your API key as an environment variable, replace
$DASHSCOPE_API_KEYwith your actual API key.# ======= Important ======= # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # === Delete this comment before execution === 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
API description
def delete_vocabulary(self, vocabulary_id: str) -> None: ''' Delete a hotword list. param: vocabulary_id The identifier of the hotword list to delete. '''Code example
import dashscope from dashscope.audio.asr import * import os # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # If you have not configured an environment variable, replace the following line with your Model Studio API key: dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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")
Java SDK
API description
/** * Delete a hotword list. * * @param vocabularyId The hotword list 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, InputRequiredExceptionCode example
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 { // API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key // If you have not configured an environment variable, replace the following line with your Model Studio 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 { // The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1 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"); } }
RESTful API
URL
China (Beijing):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationSingapore (International):
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationRequest headers
Parameter
Type
Required
Description
Authorization
string
The authentication token. The format is
Bearer <your_api_key>. Replace<your_api_key>with your actual API key.Content-Type
string
The media type of the data transferred in the request body. Set the value to
application/json.Request body
The following request body includes all request parameters. You can omit optional fields as needed.
Importantmodel: The custom hotword model. Set the value tospeech-biasing.{ "model": "speech-biasing", "input": { "action": "delete_vocabulary", "vocabulary_id": "vocab-testpfx-xxx" } }Request parameters
Parameter
Type
Default
Required
Description
model
string
-
The custom hotword model. Set the value to
speech-biasing.action
string
-
The operation type. Set the value to
delete_vocabulary.vocabulary_id
string
-
The ID of the hotword list to delete.
Response parameters
Code example
The following is a cURL example. For Java and Python examples, see the corresponding SDKs.
If you have not configured your API key as an environment variable, replace
$DASHSCOPE_API_KEYwith your actual API key.# ======= Important ======= # The following is the URL for the Singapore region. If you use a model in the China (Beijing) region, replace the URL with: https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization # API keys for the Singapore and China (Beijing) regions are different. To obtain an API key, see https://www.alibabacloud.com/help/en/model-studio/get-api-key # === Delete this comment before execution === 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" } }'
Error codes
If an error occurs, see Error messages for troubleshooting information.