音声認識タスクで、製品名や固有名詞などの特定のビジネス用語が正確に認識されない場合に、ホットワード機能を使用できます。これらの用語をホットワードとして追加することで、優先的に処理され、認識の精度を向上させることができます。
ホットワードの概要
ホットワード機能では、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` で言語を指定した場合、他の言語のホットワードは機能しません。 |
サポート対象モデル
モデルを選択する前に、モデルシリーズによって使用される認識最適化技術が異なることに注意してください:
ホットワード:この機能は、事前定義された単語リストを使用して特定の用語の認識精度を向上させるのに適しています。サポート対象モデルは以下のとおりです。
コンテキストバイアス:この機能は、インテリジェントで柔軟な動的認識最適化に適しています。Qwen 音声認識モデルはこの技術を使用しており、ホットワードはサポートしていません。詳細については、「リアルタイム音声認識 - Qwen - コンテキストバイアス」および「音声ファイル認識 - Qwen - コンテキストバイアス」をご参照ください。
国際(シンガポール)
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/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'
# 次の 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/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";
// 次の 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:ホットワードリストを使用するように設定された音声認識モデルです。このモデルは、後続の音声認識 API 呼び出しで使用されるモデルと一致する必要があります。def create_vocabulary(self, target_model: str, prefix: str, vocabulary: List[dict]) -> str: ''' ホットワードリストを作成します。 param: target_model ホットワードリスト用の音声認識モデル。後続の API 呼び出しで使用されるモデルと一致する必要があります。 param: prefix ホットワードリストのカスタムプレフィックス。数字と小文字のみを使用し、10 文字未満にしてください。 param: vocabulary ホットワードリストの JSON。 return: ホットワードリスト ID。 '''コード例
import dashscope from dashscope.audio.asr import * import os # シンガポールリージョンと中国 (北京) リージョンの API キーは異なります。API キーの取得:https://www.alibabacloud.com/help/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:ホットワードリストを使用するように設定された音声認識モデルです。このモデルは、後続の音声認識 API 呼び出しで使用されるモデルと一致する必要があります。/** * 新しいホットワードリストを作成します。 * * @param targetModel ホットワードリスト用の音声認識モデル。後続の API 呼び出しで使用されるモデルと一致する必要があります。 * @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/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("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
中国 (北京):
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:ホットワードリストを使用するように設定された音声認識モデルです。このモデルは、後続の音声認識 API 呼び出しで使用されるモデルと一致する必要があります。
{ "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
-
ホットワードリストを使用する音声認識モデルです。詳細については、「サポート対象モデル」をご参照ください。
後続の音声認識 API 呼び出しで使用されるモデルと一致する必要があります。
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# ======= 重要 ======= # 次の URL はシンガポールリージョン用です。中国 (北京) リージョンのモデルを使用する場合は、https://dashscope.aliyuncs.com/api/v1/services/audio/asr/customization に置き換えてください。 # シンガポールリージョンと中国 (北京) リージョンの API キーは異なります。API キーの取得:https://www.alibabacloud.com/help/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": "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 カスタムプレフィックス。設定した場合、このプレフィックスを持つホットワードリスト ID のみを返します。 param: page_index ページインデックス。 param: page_size ページサイズ。 return: ホットワードリスト識別子のリスト。 '''コード例
import dashscope from dashscope.audio.asr import * import json import os # シンガポールリージョンと中国 (北京) リージョンの API キーは異なります。API キーの取得:https://www.alibabacloud.com/help/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 list: {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 ページサイズ。 * @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/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 list: " + 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/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/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
ホットワードリストを使用する音声認識モデルです。詳細については、「サポート対象モデル」をご参照ください。
後続の音声認識 API 呼び出しで使用されるモデルと一致する必要があります。
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/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
ホットワードリストを使用する音声認識モデルです。詳細については、「サポート対象モデル」をご参照ください。
後続の音声認識 API 呼び出しで使用されるモデルと一致する必要があります。
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
ホットワードリストを使用する音声認識モデルです。詳細については、「サポート対象モデル」をご参照ください。
後続の音声認識 API 呼び出しで使用されるモデルと一致する必要があります。
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/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/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/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("Queli Renjia", 4, "zh")); for (Hotword word : wordList) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("text", word.text); jsonObject.addProperty("weight", word.weight); jsonObject.addProperty("lang", word.lang); vocabularyJson.add(jsonObject); } VocabularyService service = new VocabularyService(apiKey); // 実際のホットワードリスト ID に置き換えてください。 service.updateVocabulary("vocab-testpfx-xxx", vocabularyJson); } } class Hotword { String text; int weight; String lang; public Hotword(String text, int weight, String lang) { this.text = text; this.weight = weight; this.lang = lang; } }
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/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/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/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/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" } }'
エラーコード
エラーが発生した場合は、「エラーメッセージ」でトラブルシューティング情報をご参照ください。