リクエスト本文 | 非ストリーミング出力PythonDashScope Python SDK の SpeechSynthesizer インターフェイスは、MultiModalConversation インターフェイスに統合されました。そのメソッドとパラメーターは同じままです。 # DashScope SDK の最新バージョンをインストールします。
import os
import dashscope
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
text = "Let me recommend a T-shirt. It is absolutely gorgeous. The color is very flattering, and it is a perfect piece for any outfit. You cannot go wrong with this one. It is really beautiful and flattering for all body types. It looks great on everyone. I highly recommend this T-shirt."
# SpeechSynthesizer インターフェイスの使用法: dashscope.audio.qwen_tts.SpeechSynthesizer.call(...)
response = dashscope.MultiModalConversation.call(
# Qwen-TTS シリーズのモデルのみがサポートされています。他のモデルは使用しないでください。
model="qwen3-tts-flash",
# シンガポールリージョンと北京リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください。
# 環境変数を設定していない場合は、次の行を Model Studio API キーを使用して api_key="sk-xxx" に置き換えてください。
api_key=os.getenv("DASHSCOPE_API_KEY"),
text=text,
voice="Cherry",
language_type="Chinese"
)
print(response)
Java// DashScope SDK の最新バージョンをインストールします。
import com.alibaba.dashscope.aigc.multimodalconversation.AudioParameters;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
public class Main {
private static final String MODEL = "qwen3-tts-flash";
public static void call() throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalConversationParam param = MultiModalConversationParam.builder()
// Qwen-TTS シリーズのモデルのみがサポートされています。他のモデルは使用しないでください。
.model(MODEL)
// シンガポールリージョンと北京リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください。
// 環境変数を設定していない場合は、次の行を Model Studio API キーを使用して apiKey("sk-xxx") に置き換えてください。
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.text("Today is a wonderful day to build something people love!")
.voice(AudioParameters.Voice.CHERRY)
.languageType("English")
.build();
MultiModalConversationResult result = conv.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
try {
call();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
curl# ======= 重要事項 =======
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation に置き換えてください。
# シンガポールリージョンと北京リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください。
# 環境変数を設定していない場合は、$DASHSCOPE_API_KEY を Model Studio API キー (sk-xxx など) に置き換えてください。
# === 実行前にこのコメントを削除してください ===
curl -X POST 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen3-tts-flash",
"input": {
"text": "Let me recommend a T-shirt. It is absolutely gorgeous. The color is very flattering, and it is a perfect piece for any outfit. You cannot go wrong with this one. It is really beautiful and flattering for all body types. It looks great on everyone. I highly recommend this T-shirt.",
"voice": "Cherry",
"language_type": "Chinese"
}
}'
ストリーミング出力PythonDashScope Python SDK の SpeechSynthesizer インターフェイスは、MultiModalConversation インターフェイスに統合されました。新しいインターフェイスを使用するには、名前を置き換えるだけです。他のすべてのパラメーターは完全に互換性があります。 # DashScope SDK のバージョンは 1.24.5 以降である必要があります。
import os
import dashscope
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
text = "Let me recommend a T-shirt. It is absolutely gorgeous. The color is very flattering, and it is a perfect piece for any outfit. You cannot go wrong with this one. It is really beautiful and flattering for all body types. It looks great on everyone. I highly recommend this T-shirt."
# SpeechSynthesizer インターフェイスの使用法: dashscope.audio.qwen_tts.SpeechSynthesizer.call(...)
response = dashscope.MultiModalConversation.call(
model="qwen3-tts-flash",
# シンガポールリージョンと北京リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください。
# 環境変数を設定していない場合は、次の行を Model Studio API キーを使用して api_key="sk-xxx" に置き換えてください。
api_key=os.getenv("DASHSCOPE_API_KEY"),
text=text,
voice="Cherry",
language_type="Chinese"
stream=True
)
for chunk in response:
print(chunk)
Java// DashScope SDK のバージョンは 2.19.0 以降である必要があります。
import com.alibaba.dashscope.aigc.multimodalconversation.AudioParameters;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import io.reactivex.Flowable;
import com.alibaba.dashscope.utils.Constants;
public class Main {
private static final String MODEL = "qwen3-tts-flash";
public static void streamCall() throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalConversationParam param = MultiModalConversationParam.builder()
.model(MODEL)
// シンガポールリージョンと北京リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください。
// 環境変数を設定していない場合は、次の行を Model Studio API キーを使用して .apiKey("sk-xxx") に置き換えてください。
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.text("Today is a wonderful day to build something people love!")
.voice(AudioParameters.Voice.CHERRY)
.languageType("English")
.build();
Flowable<MultiModalConversationResult> result = conv.streamCall(param);
result.blockingForEach(r -> {System.out.println(JsonUtils.toJson(r));
});
}
public static void main(String[] args) {
// 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
try {
streamCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
curl# ======= 重要事項 =======
# 次の URL はシンガポールリージョン用です。北京リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation に置き換えてください。
# シンガポールリージョンと北京リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key にアクセスしてください。
# 環境変数を設定していない場合は、$DASHSCOPE_API_KEY を Model Studio API キー (sk-xxx など) に置き換えてください。
# === 実行前にこのコメントを削除してください ===
curl -X POST 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-H 'X-DashScope-SSE: enable' \
-d '{
"model": "qwen3-tts-flash",
"input": {
"text": "Let me recommend a T-shirt. It is absolutely gorgeous. The color is very flattering, and it is a perfect piece for any outfit. You cannot go wrong with this one. It is really beautiful and flattering for all body types. It looks great on everyone. I highly recommend this T-shirt.",
"voice": "Cherry",
"language_type": "Chinese"
}
}'
Base64 オーディオをリアルタイムで再生する方法の詳細については、「リアルタイム再生」をご参照ください。 |
model string (必須) モデル名。サポートされているモデルのリストについては、「Qwen-TTS」をご参照ください。 |
text string (必須) 合成するテキスト。モデルは、中国語、英語、またはその両方の混合テキストをサポートしています。Qwen-TTS モデルの最大入力は 512 トークンです。Qwen3-TTS モデルの最大入力は 600 文字です。 |
voice string (必須) 使用する音声。詳細については、「サポートされている音声」をご参照ください。 |
language_type string (オプション) 合成された音声の言語を指定します。デフォルト値は Auto です。 |
stream boolean (オプション) デフォルト値は false です。 ストリームで応答を返すかどうかを指定します。有効な値: このパラメーターは Python SDK でのみサポートされています。Java SDK を使用してストリーミング出力を実装するには、streamCall インターフェイスを呼び出します。HTTP 経由でストリーミング出力を実装するには、ヘッダーで X-DashScope-SSE を enable に設定します。 |