音声認識タスクにおいて、製品名や固有名詞などの特定のビジネス関連用語が不正確に認識される場合、ホットワード機能を使用できます。これらの用語をホットワードとして追加することで、優先的に処理され、最終的な認識の精度が向上します。
ホットワードの概要
ホットワード機能は、語彙エントリの JSON 配列を送信することで、特定の単語の認識精度を向上させます。配列内の各オブジェクトは、1 つのホットワードとそのプロパティを定義します。
例 :映画名の認識精度を向上させる (Fun-ASR および Paraformer シリーズモデルに適用)
[
{"text": "Seediq Bale", "weight": 4, "lang": "en"},
{"text": "Goodbye Mr. Loser", "weight": 4, "lang": "en"},
{"text": "Confucius' Family", "weight": 4, "lang": "en"}
]フィールドの説明:
フィールド | 型 | 必須 | 説明 |
text | string | ホットワードのテキストです。 ホットワードのテキストに使用する言語は、選択したモデルでサポートされている必要があります。モデルによってサポートされる言語は異なります。 ホットワードは認識または翻訳精度を向上させるため、任意の文字列ではなく実在する単語を使用してください。ホットワードの長さ制限は以下のとおりです。
| |
weight | int | ホットワードの重みです。一般的な値は 4 です。 有効値:[1, 5]。 結果が不十分な場合は、重みを少し上げてください。ただし、重みを高くしすぎると他の単語の認識精度に悪影響を及ぼす可能性があります。 | |
lang | string | 言語コードです。音声認識(ASR)におけるホットワード強化の言語を指定するために使用します。事前に言語を特定できない場合は、このフィールドを省略してください。その場合、モデルが自動的に検出します。 言語コードのマッピングについては、ご利用のモデルの API 製品ページをご参照ください。音声認識サービスを呼び出す際は、指定する言語が language_hints パラメーターと一致していることを確認してください。一致しない場合、他の言語のホットワードは無視されます。 |
サポートされるモデル
シンガポール
Fun-ASR:
リアルタイム音声認識: fun-asr-realtime、fun-asr-realtime-2025-11-07
音声ファイル認識: fun-asr、fun-asr-2025-11-07、fun-asr-2025-08-25、fun-asr-mtl、fun-asr-mtl-2025-08-25
中国 (北京)
Fun-ASR:
リアルタイム音声認識: fun-asr-realtime、fun-asr-realtime-2025-11-07、fun-asr-realtime-2025-09-15
音声ファイル認識: fun-asr、fun-asr-2025-11-07、fun-asr-2025-08-25、fun-asr-mtl、fun-asr-mtl-2025-08-25
Paraformer:
リアルタイム音声認識: paraformer-realtime-v2、paraformer-realtime-8k-v2
音声ファイル認識: paraformer-v2、paraformer-8k-v2
課金
ホットワード機能は無料です。
ホットワードの制限
各アカウントは最大 10 個のホットワードリストを作成できます (すべてのモデルで共有)。この制限の引き上げを希望する場合は、リクエストを送信してください。
各ホットワードリストには最大 500 個のホットワードを含めることができます。
はじめに:ホットワードの作成から使用まで
ワークフロー
ホットワードリストの作成と音声認識での使用は、密接に関連する 2 つの独立したステップです。最初に作成し、次に使用するという順序に従ってください。
ホットワードリストを作成します。
ホットワードリスト作成 API を呼び出します。このホットワードリストを使用する音声認識モデルを宣言するために、
target_model(Java:targetModel) を指定する必要があります。すでにホットワードリストがある場合 (すべてのホットワードリストの表示 API を使用して確認)、このステップをスキップして次に進んでください。
音声認識にホットワードリストを使用します。
音声認識 API を呼び出し、ホットワードリスト ID を渡します。ここで使用する音声認識モデルは、ホットワードリストの作成時に指定した
target_model(Java:targetModel) と一致している必要があります。
事前準備
API キーの取得:API キーを取得します。セキュリティのため、API キーを環境変数として設定してください。
SDK のインストール:最新の DashScope SDK がインストールされていることを確認してください。
サンプルコード
このサンプルでは、次の音声ファイルを使用します:asr_example.wav。
Python
import dashscope
from dashscope.audio.asr import *
import os
# API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key
# 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:dashscope.api_key = "sk-xxx"
dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY')
# シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
# シンガポールリージョンの WebSocket URL。北京リージョンのモデルの場合は、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 キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key
// 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:public static String apiKey = "sk-xxx"
public static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void main(String[] args) throws NoApiKeyException, InputRequiredException {
// シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
// シンガポールリージョンの WebSocket URL。北京リージョンのモデルの場合は、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();
// 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 リファレンス
異なる API を使用する場合、すべての操作で同じアカウントを使用していることを確認してください。
ホットワードリストの作成
ホットワードリストの JSON フォーマットについては、「ホットワードの概要」をご参照ください。
Python SDK
API の説明
重要target_model:このホットワードリストを使用する音声認識モデル。後の音声認識呼び出しで使用されるモデルと一致する必要があります。def create_vocabulary(self, target_model: str, prefix: str, vocabulary: List[dict]) -> str: ''' ホットワードリストを作成します。 param: target_model このホットワードリストに関連付けられる音声認識モデル。後の音声認識呼び出しで使用されるモデルと一致する必要があります。 param: prefix ホットワードリストのカスタムプレフィックス。数字と小文字のみ使用可能。10 文字未満である必要があります。 param: vocabulary JSON フォーマットのホットワードリスト。 return: ホットワードリスト ID。 '''サンプルコード
import dashscope from dashscope.audio.asr import * import os # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # シンガポールリージョンの URL。北京リージョンのモデルの場合は、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} ] # ホットワードリストの作成 service = VocabularyService() vocabulary_id = service.create_vocabulary( prefix=prefix, target_model=target_model, vocabulary=my_vocabulary) print(f"Hotword list ID: {vocabulary_id}")
Java SDK
API の説明
重要targetModel:このホットワードリストを使用する音声認識モデル。後の音声認識呼び出しで使用されるモデルと一致する必要があります。/** * 新しいホットワードリストを作成します。 * * @param targetModel このホットワードリストに関連付けられる音声認識モデル。後の音声認識呼び出しで使用されるモデルと一致する必要があります。 * @param prefix ホットワードリストのカスタムプレフィックス。数字と小文字のみ使用可能。10 文字未満である必要があります。 * @param vocabulary JSON フォーマットのホットワードリスト。 * @return ホットワードリストオブジェクト。 * @throws NoApiKeyException API キーが空の場合。 * @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 { // API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key // 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:public static String apiKey = "sk-xxx" public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // シンガポールリージョンの URL。北京リージョンのモデルの場合は、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("Confucius' Family", 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
中国 (北京):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationシンガポール:
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationリクエストヘッダー
パラメーター
タイプ
必須
説明
Authorization
string
認証トークン。フォーマットは
Bearer <your_api_key>です。「<your_api_key>」を実際の API キーに置き換えてください。Content-Type
string
リクエストボディ内のデータのメディアタイプ。
application/jsonに固定されています。リクエストボディ
リクエストボディにはすべてのパラメーターが含まれます。オプションのフィールドは必要に応じて省略してください。
重要以下のパラメーターの違いに注意してください:
model:ホットワードカスタマイズモデル。speech-biasingに固定されています。target_model:このホットワードリストを使用する音声認識モデル。後の音声認識呼び出しで使用されるモデルと一致する必要があります。
{ "model": "speech-biasing", "input": { "action": "create_vocabulary", "target_model": "fun-asr", "prefix": "testpfx", "vocabulary": [ {"text": "Seediq Bale", "weight": 4, "lang": "zh"} ] } }リクエストパラメーター
パラメーター
タイプ
デフォルト
必須
説明
model
string
-
ホットワードカスタマイズモデル。
speech-biasingに固定されています。action
string
-
操作タイプ。
create_vocabularyに固定されています。target_model
string
-
このホットワードリストを使用する音声認識モデル。詳細については、「サポートされるモデル」をご参照ください。
後の音声認識呼び出しで使用されるモデルと一致する必要があります。
prefix
string
-
ホットワードリストに認識可能な名前を割り当てます (数字と小文字のみ、10 文字未満)。
このプレフィックスはホットワードリスト ID に表示されます。例えば、プレフィックスが「testpfx」の場合、最終的な ID は「vocab-testpfx-51773d05xxxxxx」となります。
vocabulary
array[object]
-
JSON フォーマットのホットワードリスト。詳細については、「ホットワードの概要」をご参照ください。
レスポンスパラメーター
主要なパラメーター:
パラメーター
タイプ
説明
vocabulary_id
string
ホットワードリスト ID。
サンプルコード
cURL の例 (Java および Python については、それぞれの SDK サンプルをご参照ください)。
API キーを環境変数として設定していない場合は、
$DASHSCOPE_API_KEYを実際の API キーに置き換えてください。https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customization<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># ======= 重要事項 ======= # シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization に置き換えてください # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # === 実行前にこのコメントを削除してください === 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} ] } }'
すべてのホットワードリストの表示
Python SDK
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 1 ページあたりのアイテム数。 return: ホットワードリスト識別子のリスト。 '''サンプルコード
import dashscope from dashscope.audio.asr import * import json import os # API キーは、シンガポールリージョンと北京リージョンで異なります。API キーの取得: https://www.alibabacloud.com/help/zh/model-studio/get-api-key # 環境変数を設定していない場合は、次の行をお使いの Model Studio API キーに置き換えてください: dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # シンガポールリージョン用の URL。北京リージョンのモデルの場合は、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 lists: {json.dumps(vocabularies)}")レスポンスパラメーター
主要なパラメーター:
パラメーター
タイプ
説明
vocabulary_id
string
ホットワードリスト ID。
gmt_create
string
ホットワードリストが作成された時間。
gmt_modified
string
ホットワードリストが最後に変更された時間。
status
string
ステータス:
OK:使用準備完了。
UNDEPLOYED:使用準備未完了。
Java SDK
API の説明
/** * 作成されたすべてのホットワードリストを表示します。デフォルトのページインデックスは 0、デフォルトのページサイズは 10 です。 * * @param prefix ホットワードリストのカスタムプレフィックス。 * @return ホットワードリストオブジェクトの配列。 * @throws NoApiKeyException API キーが空の場合。 * @throws InputRequiredException 必須パラメーターが欠落している場合。 */ public Vocabulary[] listVocabulary(String prefix) throws NoApiKeyException, InputRequiredException /** * 作成されたすべてのホットワードリストを表示します。 * * @param prefix ホットワードリストのカスタムプレフィックス。 * @param pageIndex クエリするページインデックス。 * @param pageSize 1 ページあたりのアイテム数。 * @return ホットワードリストオブジェクトの配列。 * @throws NoApiKeyException API キーが空の場合。 * @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 { // API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key // 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:public static String apiKey = "sk-xxx" public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // シンガポールリージョンの URL。北京リージョンのモデルの場合は、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 lists: " + gson.toJson(vocabularies)); } }主要なパラメーター:
パラメーター
タイプ
説明
vocabulary_id
string
ホットワードリスト ID。
gmt_create
string
ホットワードリストが作成された時間。
gmt_modified
string
ホットワードリストが最後に変更された時間。
status
string
ステータス:
OK:使用準備完了。
UNDEPLOYED:使用準備未完了。
RESTful API
URL
中国 (北京):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationシンガポール:
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationリクエストヘッダー
パラメーター
タイプ
必須
説明
Authorization
string
認証トークン。フォーマットは
Bearer <your_api_key>です。「<your_api_key>」を実際の API キーに置き換えてください。Content-Type
string
リクエストボディ内のデータのメディアタイプ。
application/jsonに固定されています。リクエストボディ
リクエストボディにはすべてのパラメーターが含まれます。オプションのフィールドは必要に応じて省略してください。
重要model:ホットワードカスタマイズモデル。speech-biasingに固定されています。{ "model": "speech-biasing", "input": { "action": "list_vocabulary", "prefix": "testpfx", "page_index": 0, "page_size": 10 } }リクエストパラメーター
パラメーター
タイプ
デフォルト
必須
説明
model
string
-
ホットワードカスタマイズモデル。
speech-biasingに固定されています。action
string
-
操作タイプ。
list_vocabularyに固定されています。prefix
string
-
ホットワードリストのカスタムプレフィックス。数字と小文字のみ使用可能。10 文字未満。
page_index
integer
0
ページインデックス。0 から始まります。
page_size
integer
10
1 ページあたりのアイテム数。
レスポンスパラメーター
主要なパラメーター:
パラメーター
タイプ
説明
vocabulary_id
string
ホットワードリスト ID。
gmt_create
string
ホットワードリストが作成された時間。
gmt_modified
string
ホットワードリストが最後に変更された時間。
status
string
ステータス:
OK:使用準備完了。
UNDEPLOYED:使用準備未完了。
サンプルコード
cURL の例 (Java および Python については、それぞれの SDK サンプルをご参照ください)。
API キーを環境変数として設定していない場合は、
$DASHSCOPE_API_KEYを実際の API キーに置き換えてください。# ======= 重要事項 ======= # シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization に置き換えてください # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # === 実行前にこのコメントを削除してください === 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 } }'
特定のホットワードリストの照会
ID で特定のホットワードリストを照会する場合、レスポンスには ID フィールドは含まれません。
Python SDK
API の説明
def query_vocabulary(self, vocabulary_id: str) -> List[dict]: ''' ホットワードリストの内容を取得します。 param: vocabulary_id ホットワードリストの識別子。 return: ホットワードリスト。 '''サンプルコード
import dashscope from dashscope.audio.asr import * import json import os # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1' service = VocabularyService() # 実際のホットワードリスト ID に置き換えてください vocabulary = service.query_vocabulary("vocab-testpfx-xxx") print(f"Hotword list: {json.dumps(vocabulary, ensure_ascii=False)}")レスポンスパラメーター
主要なパラメーター:
パラメーター
タイプ
説明
vocabulary
object[]
ホットワードリストの辞書。フィールドの意味については、「ホットワードの概要」をご参照ください。
gmt_create
string
ホットワードリストが作成された時間。
gmt_modified
string
ホットワードリストが最後に変更された時間。
target_model
string
このホットワードリストを使用する音声認識モデル。詳細については、「サポートされるモデル」をご参照ください。
後の音声認識呼び出しで使用されるモデルと一致する必要があります。
status
string
ステータス:
OK:使用準備完了。
UNDEPLOYED:使用準備未完了。
Java SDK
API の説明
/** * 特定のホットワードリストを照会します。 * * @param vocabularyId 照会するホットワードリスト。 * @return ホットワードリストオブジェクト。 * @throws NoApiKeyException API キーが空の場合。 * @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 { // API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key // 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:public static String apiKey = "sk-xxx" public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください Constants.baseHttpApiUrl = "https://dashscope-intl.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("Hotword list: " + gson.toJson(vocabulary.getData())); } }レスポンスパラメーター
主要なパラメーター:
パラメーター
タイプ
説明
vocabulary
object[]
ホットワードリストの辞書。フィールドの意味については、「ホットワードの概要」をご参照ください。
gmt_create
string
ホットワードリストが作成された時間。
gmt_modified
string
ホットワードリストが最後に変更された時間。
target_model
string
このホットワードリストを使用する音声認識モデル。詳細については、「サポートされるモデル」をご参照ください。
後の音声認識呼び出しで使用されるモデルと一致する必要があります。
status
string
ステータス:
OK:使用準備完了。
UNDEPLOYED:使用準備未完了。
RESTful API
URL
中国 (北京):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationシンガポール:
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationリクエストヘッダー
パラメーター
タイプ
必須
説明
Authorization
string
認証トークン。フォーマットは
Bearer <your_api_key>です。「<your_api_key>」を実際の API キーに置き換えてください。Content-Type
string
リクエストボディ内のデータのメディアタイプ。
application/jsonに固定されています。リクエストボディ
リクエストボディにはすべてのパラメーターが含まれます。オプションのフィールドは必要に応じて省略してください。
重要model:ホットワードカスタマイズモデル。speech-biasingに固定されています。{ "model": "speech-biasing", "input": { "action": "query_vocabulary", "vocabulary_id": "vocab-testpfx-xxxx" } }リクエストパラメーター
パラメーター
タイプ
デフォルト
必須
説明
model
string
-
ホットワードカスタマイズモデル。
speech-biasingに固定されています。action
string
-
操作タイプ。
query_vocabularyに固定されています。vocabulary_id
string
-
照会するホットワードリストの ID。
レスポンスパラメーター
主要なパラメーター:
パラメーター
タイプ
説明
vocabulary
object[]
ホットワードリストの辞書。フィールドの意味については、「ホットワードの概要」をご参照ください。
gmt_create
string
ホットワードリストが作成された時間。
gmt_modified
string
ホットワードリストが最後に変更された時間。
target_model
string
このホットワードリストを使用する音声認識モデル。詳細については、「サポートされるモデル」をご参照ください。
後の音声認識呼び出しで使用されるモデルと一致する必要があります。
status
string
ステータス:
OK:使用準備完了。
UNDEPLOYED:使用準備未完了。
サンプルコード
cURL の例 (Java および Python については、それぞれの SDK サンプルをご参照ください)。
API キーを環境変数として設定していない場合は、
$DASHSCOPE_API_KEYを実際の API キーに置き換えてください。# ======= 重要事項 ======= # シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization に置き換えてください # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # === 実行前にこのコメントを削除してください === 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" } }'
ホットワードリストの更新
Python SDK
API の説明
def update_vocabulary(self, vocabulary_id: str, vocabulary: List[dict]) -> None: ''' 既存のホットワードリストを新しいものに置き換えます。 param: vocabulary_id 置き換えるホットワードリストの識別子。 param: vocabulary 新しいホットワードリスト。 '''サンプルコード
import dashscope from dashscope.audio.asr import * import os # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # シンガポールリージョンの URL。北京リージョンのモデルの場合は、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"} ] # 実際のホットワードリスト ID に置き換えてください service.update_vocabulary("vocab-testpfx-xxx", my_vocabulary)
Java SDK
API の説明
/** * ホットワードリストを更新します。 * * @param vocabularyId 更新するホットワードリスト。 * @param vocabulary 新しいホットワードリスト。 * @throws NoApiKeyException API キーが空の場合。 * @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 { // API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key // 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:public static String apiKey = "sk-xxx" public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // シンガポールリージョンの URL。北京リージョンのモデルの場合は、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("Confucius' Family", 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; } }
RESTful API
URL
中国 (北京):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationシンガポール:
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationリクエストヘッダー
パラメーター
タイプ
必須
説明
Authorization
string
認証トークン。フォーマットは
Bearer <your_api_key>です。「<your_api_key>」を実際の API キーに置き換えてください。Content-Type
string
リクエストボディ内のデータのメディアタイプ。
application/jsonに固定されています。リクエストボディ
リクエストボディにはすべてのパラメーターが含まれます。オプションのフィールドは必要に応じて省略してください。
重要model:ホットワードカスタマイズモデル。speech-biasingに固定されています。{ "model": "speech-biasing", "input": { "action": "update_vocabulary", "vocabulary_id": "vocab-testpfx-6977ae49f65c4c3db054727cxxxxxxxx", "vocabulary": [ {"text": "Seediq Bale", "weight": 4, "lang": "zh"} ] } }リクエストパラメーター
パラメーター
タイプ
デフォルト
必須
説明
model
string
-
ホットワードカスタマイズモデル。
speech-biasingに固定されています。action
string
-
操作タイプ。
update_vocabularyに固定されています。vocabulary_id
string
-
更新するホットワードリストの ID。
vocabulary
object[]
-
更新されたホットワードリストの辞書。フィールドの意味については、「ホットワードの概要」をご参照ください。
レスポンスパラメーター
サンプルコード
cURL の例 (Java および Python については、それぞれの SDK サンプルをご参照ください)。
API キーを環境変数として設定していない場合は、
$DASHSCOPE_API_KEYを実際の API キーに置き換えてください。# ======= 重要事項 ======= # シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization に置き換えてください # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # === 実行前にこのコメントを削除してください === 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"} ] } }'
ホットワードリストの削除
Python SDK
API の説明
def delete_vocabulary(self, vocabulary_id: str) -> None: ''' ホットワードリストを削除します。 param: vocabulary_id 削除するホットワードリストの識別子。 '''サンプルコード
import dashscope from dashscope.audio.asr import * import os # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:dashscope.api_key = "sk-xxx" dashscope.api_key = os.environ.get('DASHSCOPE_API_KEY') # シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1' service = VocabularyService() # 実際のホットワードリスト ID に置き換えてください service.delete_vocabulary("vocab-testpfx-xxxx")
Java SDK
API の説明
/** * ホットワードリストを削除します。 * * @param vocabularyId 削除するホットワードリスト。 * @throws NoApiKeyException API キーが空の場合。 * @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 { // API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key // 環境変数を設定していない場合は、次の行を実際の Model Studio API キーに置き換えてください:public static String apiKey = "sk-xxx" public static String apiKey = System.getenv("DASHSCOPE_API_KEY"); public static void main(String[] args) throws NoApiKeyException, InputRequiredException { // シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1"; VocabularyService service = new VocabularyService(apiKey); // 削除する際は、実際のホットワードリスト ID に置き換えてください service.deleteVocabulary("vocab-testpfx-xxxx"); } }
RESTful API
URL
中国 (北京):
POST https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customizationシンガポール:
POST https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/customizationリクエストヘッダー
パラメーター
タイプ
必須
説明
Authorization
string
認証トークン。フォーマットは
Bearer <your_api_key>です。「<your_api_key>」を実際の API キーに置き換えてください。Content-Type
string
リクエストボディ内のデータのメディアタイプ。
application/jsonに固定されています。リクエストボディ
リクエストボディにはすべてのパラメーターが含まれます。オプションのフィールドは必要に応じて省略してください。
重要model:ホットワードカスタマイズモデル。speech-biasingに固定されています。{ "model": "speech-biasing", "input": { "action": "delete_vocabulary", "vocabulary_id": "vocab-testpfx-xxx" } }リクエストパラメーター
パラメーター
タイプ
デフォルト
必須
説明
model
string
-
ホットワードカスタマイズモデル。
speech-biasingに固定されています。action
string
-
操作タイプ。
delete_vocabularyに固定されています。vocabulary_id
string
-
削除するホットワードリストの ID。
レスポンスパラメーター
サンプルコード
cURL の例 (Java および Python については、それぞれの SDK サンプルをご参照ください)。
API キーを環境変数として設定していない場合は、
$DASHSCOPE_API_KEYを実際の API キーに置き換えてください。# ======= 重要事項 ======= # シンガポールリージョンの URL。北京リージョンのモデルの場合は、https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization に置き換えてください # API キーはシンガポールリージョンと北京リージョンで異なります。API キーの取得:https://www.alibabacloud.com/help/ja/model-studio/get-api-key # === 実行前にこのコメントを削除してください === 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" } }'
エラーコード
エラーが発生した場合は、「エラーメッセージ」を参照してトラブルシューティングを行ってください。