Request body |
Antarmuka SpeechSynthesizer dalam SDK Python DashScope kini telah disatukan ke dalam MultiModalConversation. Penggunaan dan parameternya tetap sepenuhnya konsisten.
# Instal versi terbaru SDK DashScope
import os
import dashscope
# Wilayah Singapura
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
text = "Let me recommend a T-shirt to everyone. This one is really super nice. The color is very elegant, and it's also a perfect item to match. Everyone can buy it without hesitation. It's truly beautiful and very forgiving on the figure. No matter what body type you have, it will look great. I recommend everyone to place an order."
# Penggunaan antarmuka SpeechSynthesizer: dashscope.audio.qwen_tts.SpeechSynthesizer.call(...)
response = dashscope.MultiModalConversation.call(
# Untuk menggunakan fitur kontrol instruksi, ganti model dengan qwen3-tts-instruct-flash
model="qwen3-tts-flash",
# Kunci API untuk wilayah Singapura dan Beijing berbeda. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
# Jika variabel lingkungan belum dikonfigurasi, ganti baris berikut dengan Kunci API Model Studio Anda: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
text=text,
voice="Cherry"
# Untuk menggunakan fitur kontrol instruksi, hapus komentar baris berikut dan ganti model dengan qwen3-tts-instruct-flash
# instructions='Fast speech rate, with a clear rising intonation, suitable for introducing fashion products.',
# optimize_instructions=True
)
print(response)
// Instal versi terbaru SDK DashScope
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 {
// Untuk menggunakan fitur kontrol instruksi, ganti MODEL dengan qwen3-tts-instruct-flash
private static final String MODEL = "qwen3-tts-flash";
public static void call() throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalConversationParam param = MultiModalConversationParam.builder()
.model(MODEL)
// Kunci API untuk wilayah Singapura dan Beijing berbeda. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
// Jika variabel lingkungan belum dikonfigurasi, ganti baris berikut dengan Kunci API Model Studio Anda: apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.text("Today is a wonderful day to build something people love!")
.voice(AudioParameters.Voice.CHERRY)
.parameter("language_type", "English")
// Untuk menggunakan fitur kontrol instruksi, hapus komentar baris berikut dan ganti MODEL dengan qwen3-tts-instruct-flash
// .parameter("instructions","Fast speech rate, with a clear rising intonation, suitable for introducing fashion products.")
// .parameter("optimize_instructions",true)
.build();
MultiModalConversationResult result = conv.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
// Wilayah Singapura
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
try {
call();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
# ======= CATATAN PENTING =======
# Wilayah Singapura
# Kunci API untuk wilayah Singapura dan Beijing berbeda. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
# Jika variabel lingkungan belum dikonfigurasi, ganti $DASHSCOPE_API_KEY dengan Kunci API Model Studio Anda: sk-xxx.
# === HAPUS KOMENTAR INI SAAT MENJALANKAN ===
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 to everyone. This one is really super nice. The color is very elegant, and it's also a perfect item to match. Everyone can buy it without hesitation. It's truly beautiful and very forgiving on the figure. No matter what body type you have, it will look great. I recommend everyone to place an order.",
"voice": "Cherry",
"language_type": "English"
}
}'
Antarmuka SpeechSynthesizer dalam SDK Python DashScope kini telah disatukan ke dalam MultiModalConversation. Untuk beralih ke antarmuka baru, cukup ganti namanya — semua parameter lainnya sepenuhnya kompatibel.
# Diperlukan SDK DashScope versi 1.24.5 atau lebih baru
import os
import dashscope
# Wilayah Singapura
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
text = "Let me recommend a T-shirt to everyone. This one is really super nice. The color is very elegant, and it's also a perfect item to match. Everyone can buy it without hesitation. It's truly beautiful and very forgiving on the figure. No matter what body type you have, it will look great. I recommend everyone to place an order."
# Penggunaan antarmuka SpeechSynthesizer: dashscope.audio.qwen_tts.SpeechSynthesizer.call(...)
response = dashscope.MultiModalConversation.call(
# Untuk menggunakan fitur kontrol instruksi, ganti model dengan qwen3-tts-instruct-flash
model="qwen3-tts-flash",
# Kunci API untuk wilayah Singapura dan Beijing berbeda. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
# Jika variabel lingkungan belum dikonfigurasi, ganti baris berikut dengan Kunci API Model Studio Anda: api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
text=text,
voice="Cherry",
# Untuk menggunakan fitur kontrol instruksi, hapus komentar baris berikut dan ganti model dengan qwen3-tts-instruct-flash
# instructions='Fast speech rate, with a clear rising intonation, suitable for introducing fashion products.',
# optimize_instructions=True,
stream=True
)
for chunk in response:
print(chunk)
// Diperlukan SDK DashScope versi 2.19.0 atau lebih baru
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;
import io.reactivex.Flowable;
public class Main {
// Untuk menggunakan fitur kontrol instruksi, ganti MODEL dengan qwen3-tts-instruct-flash
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)
// Kunci API untuk wilayah Singapura dan Beijing berbeda. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
// Jika variabel lingkungan belum dikonfigurasi, ganti baris berikut dengan Kunci API Model Studio Anda: apiKey("sk-xxx")
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.text("Today is a wonderful day to build something people love!")
.voice(AudioParameters.Voice.CHERRY)
.parameter("language_type", "English")
// Untuk menggunakan fitur kontrol instruksi, hapus komentar baris berikut dan ganti MODEL dengan qwen3-tts-instruct-flash
// .parameter("instructions","Fast speech rate, with a clear rising intonation, suitable for introducing fashion products.")
// .parameter("optimize_instructions",true)
.build();
Flowable<MultiModalConversationResult> result = conv.streamCall(param);
result.blockingForEach(r -> {System.out.println(JsonUtils.toJson(r));
});
}
public static void main(String[] args) {
// Wilayah Singapura
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
try {
streamCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
# ======= CATATAN PENTING =======
# Wilayah Singapura
# Kunci API untuk wilayah Singapura dan Beijing berbeda. Dapatkan Kunci API Anda: https://www.alibabacloud.com/help/en/model-studio/get-api-key
# Jika variabel lingkungan belum dikonfigurasi, ganti $DASHSCOPE_API_KEY dengan Kunci API Model Studio Anda: sk-xxx.
# === HAPUS KOMENTAR INI SAAT MENJALANKAN ===
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 to you. This one is truly stunning. Its color highlights your elegance and makes it an ideal match for any outfit. You can buy it without hesitation - it looks great on everyone. It flatters all body types. Whether you're tall, short, slim, or curvy, this T-shirt suits you perfectly. We highly recommend ordering it.",
"voice": "Cherry",
"language_type": "English"
}
}'
Untuk memutar audio Base64 secara real time, lihat Pemutaran streaming. |