請求體 | cURL# ======= 重要提示 =======
# 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription
# 新加坡地區和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# === 執行時請刪除該注釋 ===
curl --location --request POST 'https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/transcription' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--header "X-DashScope-Async: enable" \
--data '{
"model": "qwen3-asr-flash-filetrans",
"input": {
"file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"
},
"parameters": {
"channel_id":[
0
],
"enable_itn": false
}
}'
Javaimport com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import okhttp3.*;
import java.io.IOException;
public class Main {
// 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription
private static final String API_URL = "https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/transcription";
public static void main(String[] args) {
// 新加坡地區和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:String apiKey = "sk-xxx"
String apiKey = System.getenv("DASHSCOPE_API_KEY");
OkHttpClient client = new OkHttpClient();
Gson gson = new Gson();
/*String payloadJson = """
{
"model": "qwen3-asr-flash-filetrans",
"input": {
"file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"
},
"parameters": {
"channel_id": [0],
"enable_itn": false,
"language": "zh",
"corpus": {
"text": ""
}
}
}
""";*/
String payloadJson = """
{
"model": "qwen3-asr-flash-filetrans",
"input": {
"file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"
},
"parameters": {
"channel_id": [0],
"enable_itn": false
}
}
""";
RequestBody body = RequestBody.create(payloadJson, MediaType.get("application/json; charset=utf-8"));
Request request = new Request.Builder()
.url(API_URL)
.addHeader("Authorization", "Bearer " + apiKey)
.addHeader("Content-Type", "application/json")
.addHeader("X-DashScope-Async", "enable")
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful() && response.body() != null) {
String respBody = response.body().string();
// 用 Gson 解析 JSON
ApiResponse apiResp = gson.fromJson(respBody, ApiResponse.class);
if (apiResp.output != null) {
System.out.println("task_id: " + apiResp.output.taskId);
} else {
System.out.println(respBody);
}
} else {
System.out.println("task failed! HTTP code: " + response.code());
if (response.body() != null) {
System.out.println(response.body().string());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
static class ApiResponse {
@SerializedName("request_id")
String requestId;
Output output;
}
static class Output {
@SerializedName("task_id")
String taskId;
@SerializedName("task_status")
String taskStatus;
}
}
Pythonimport requests
import json
import os
# 以下為新加坡地區url,若使用北京地區的模型,需將url替換為:https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription
url = "https://dashscope-intl.aliyuncs.com/api/v1/services/audio/asr/transcription"
# 新加坡和北京地區的API Key不同。擷取API Key:https://www.alibabacloud.com/help/zh/model-studio/get-api-key
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:DASHSCOPE_API_KEY = "sk-xxx"
DASHSCOPE_API_KEY = os.getenv("DASHSCOPE_API_KEY")
headers = {
"Authorization": f"Bearer {DASHSCOPE_API_KEY}",
"Content-Type": "application/json",
"X-DashScope-Async": "enable"
}
payload = {
"model": "qwen3-asr-flash-filetrans",
"input": {
"file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/audios/welcome.mp3"
},
"parameters": {
"channel_id": [0],
# "language": "zh",
"enable_itn": False
# "corpus": {
# "text": ""
# }
}
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
print(f"task_id: {response.json()["output"]["task_id"]}")
else:
print("task failed!")
print(response.json())
|
model string (必選) 模型名稱。僅適用於通義千問3-ASR-Flash-Filetrans模型。 |
input object (必選) 屬性 file_url string(必選) 待識別音頻檔案URL,URL必須公網可訪問。 使用RESTful API時,若錄音檔案儲存體在阿里雲OSS,支援使用以 oss://為首碼的臨時 URL。但需注意:
重要 臨時 URL 有效期間48小時,到期後無法使用,請勿用於生產環境。 檔案上傳憑證介面限流為 100 QPS 且不支援擴容,請勿用於生產環境、高並發及壓測情境。 生產環境建議使用阿里雲OSS 等穩定儲存,確保檔案長期可用並規避限流問題。
|
parameters object (可選) 屬性 language string(可選)無預設值 若已知音訊語種,可通過該參數指定待識別語種,以提升識別準確率。 只能指定一個語種。 若音頻語種不確定,或包含多種語種(例如中英日韓混合),請勿指定該參數。 參數值: zh:中文(普通話、四川話、閩南語、吳語) yue:粵語 en:英文 ja:日語 de:德語 ko:韓語 ru:俄語 fr:法語 pt:葡萄牙語 ar:阿拉伯語 it:意大利語 es:西班牙語 hi:印地語 id:印尼語 th:泰語 tr:土耳其語 uk:烏克蘭語 vi:越南語 cs:捷克語 da:丹麥語 fil:菲律賓語 fi:芬蘭語 is:冰島語 ms:馬來語 no:挪威語 pl:波蘭語 sv:瑞典語
enable_itn boolean(可選)預設值為false 是否啟用ITN(Inverse Text Normalization,逆文本標準化)。該功能僅適用於中文和英文音頻。 參數值: text string 指定上下文(Context)。通義千問3-ASR-Flash支援使用者在語音辨識的同時,提供背景文本、實體詞表等參考資訊(Context),從而獲得定製化的識別結果。 長度限制:不超過10000 Token。 具體介紹請參見上下文增強。 channel_id array (可選)預設值為[0] 指定多音軌檔案中需進行語音辨識的音軌索引。例如:[0] 表示僅識別第一條音軌,[0, 1] 表示同時識別第一條和第二條音軌。 |