全部產品
Search
文件中心

Alibaba Cloud Model Studio:Fun-ASR錄音檔案識別HTTP API參考

更新時間:Jul 03, 2026

本文介紹Fun-ASR錄音檔案識別HTTP API的參數和介面細節。

使用者指南:非即時語音辨識。關於支援的音頻格式、檔案大小限制、時間長度限制等輸入要求,請參見音頻規格

DashScope非同步呼叫(Fun-ASR)

流程說明

與DashScope同步調用(一次請求、立即返回結果)不同,非同步呼叫專為處理長音頻檔案或耗時較長的任務設計,該模式採用“提交-輪詢”的兩步式流程,避免了因長時間等待而導致的請求逾時:

  1. 第一步:提交任務

    • 用戶端發起一個非同步處理請求。

    • 伺服器驗證請求後,不會立即執行任務,而是返回一個唯一的 task_id,表示任務已成功建立。

  2. 第二步:擷取結果

    • 用戶端使用擷取到的 task_id,通過輪詢方式反覆調用結果查詢介面。

    • 當任務處理完成後,結果查詢介面將返回最終的識別結果。

服務端點

新加坡

提交任務介面:POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/audio/asr/transcription

查詢任務介面:GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}

調用時請將{WorkspaceId}替換為真實的Workspace ID

華北2(北京)

提交任務介面:POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/asr/transcription

查詢任務介面:GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}

調用時請將{WorkspaceId}替換為真實的Workspace ID

重要

阿里雲百鍊為華北2(北京)、新加坡地區推出了業務空間專屬網域名稱,能夠為推理請求提供卓越的效能和更高的穩定性,建議遷移至新網域名稱:

  • 華北2(北京)地區:從 dashscope.aliyuncs.com 遷移至 {WorkspaceId}.cn-beijing.maas.aliyuncs.com

  • 新加坡地區:從 dashscope-intl.aliyuncs.com 遷移至 {WorkspaceId}.ap-southeast-1.maas.aliyuncs.com

{WorkspaceId}需要替換為真實的Workspace ID。現有網域名稱仍可正常使用。

重要

使用新版網域名稱(https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com)提交任務時,請求體中必須包含parameters對象。即使無需設定任何參數,也必須傳入Null 物件{},否則任務可正常提交,但識別將失敗。

要求標頭

參數

類型

是否必選

說明

Authorization

string

鑒權令牌,格式為Bearer <your_api_key>,使用時,將"<your_api_key>"替換為實際的API Key。提交任務介面和查詢任務介面均需要傳入。

Content-Type

string

請求體的媒體類型。僅提交任務介面需要傳入,固定為application/json

X-DashScope-Async

string

非同步任務標識。僅提交任務介面需要傳入,固定為enable,請勿遺漏,否則無法提交任務。

提交任務介面

提交語音辨識任務。該介面非同步返回,業務側需結合查詢任務介面輪詢任務狀態。

請求體

以下為新加坡地區的配置,調用時請將"{WorkspaceId}"替換為真實的業務空間ID,各地區的配置不同。新加坡地區和北京地區的API Key不同。

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.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": "fun-asr",
    "input": {
        "file_urls": [
            "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav"
        ]
    },
    "parameters": {
        "channel_id": [0]
    }
}'

model string (必選)

指定用於音視頻檔案轉寫的模型名。

取值範圍:

  • fun-asr

  • fun-asr-2025-11-07

  • fun-asr-2025-08-25

  • fun-asr-mtl

  • fun-asr-mtl-2025-08-25

input object (必選)

輸入參數對象。

屬性

file_urls array[string] (必選)

音視頻檔案轉寫的URL列表,支援HTTP / HTTPS協議,單次請求僅支援1個URL。關於支援的音頻格式、檔案大小限制、時間長度限制等輸入要求,請參見音頻規格

若錄音檔案儲存體在阿里雲OSS,使用RESTful API方式支援使用以oss://為首碼的臨時 URL。

重要
  • 臨時 URL 有效期間48小時,到期後無法使用,請勿用於生產環境。

  • 檔案上傳憑證介面限流為 100 QPS 且不支援擴容,請勿用於生產環境、高並發及壓測情境。

  • 生產環境建議使用阿里雲OSS 等穩定儲存,確保檔案長期可用並規避限流問題。

  • 錄音檔案URL設定成OSS臨時公網訪問不通該如何處理?要求標頭中將X-DashScope-OssResourceResolve設為enable(不推薦該方式)。

    Java SDK或者Python SDK不支援對要求標頭進行配置。

parameters object (可選)

請求參數對象。

重要

使用新版網域名稱(https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com)時,parameters為必填項。即使無需設定任何參數,也必須傳入Null 物件{}。若省略該欄位,任務可正常提交,但查詢任務結果時將返回識別失敗。

屬性

vocabulary_id string (可選)

熱詞ID,此次語音辨識中生效此熱詞ID對應的熱詞資訊。預設不啟用。使用方法請參考定製熱詞

channel_id array[integer] (可選)

指定在多音軌音頻檔案中需要識別的音軌索引,索引從 0 開始。例如,[0] 表示識別第一個音軌,[0, 1] 表示同時識別第一和第二個音軌。如果省略此參數,則預設處理第一個音軌。

重要

指定的每一個音軌都將獨立計費。例如,為單個檔案請求 [0, 1] 會產生兩筆獨立的費用。

預設值:[0]。

special_word_filter string (可選)

指定在語音辨識過程中需要處理的敏感詞,並支援對不同敏感詞設定不同的處理方式。詳情請參見敏感詞過濾

diarization_enabled boolean (可選)

是否啟用說話人分離,預設關閉。

僅適用於單聲道音頻,多頻道音訊不支援說話人分離。

啟用該功能後,識別結果中將顯示speaker_id欄位,用於區分不同說話人。

說明

如果啟用說話人分離功能,建議音頻時間長度不超過2小時,否則可能導致識別失敗或逾時。

有關speaker_id的樣本,請參見識別結果說明

預設值:false。

speaker_count integer (可選)

重要

僅在開啟說話人分離功能(diarization_enabled設定為true)時生效。

說話人數量參考值。取值範圍為2至100的整數(包含2和100)。

預設自動判斷說話人數量,如果配置此項,只能輔助演算法盡量輸出指定人數,無法保證一定會輸出此人數。

language_hints array[string] (可選)

設定待識別語言代碼。如果無法提前確定語種,可不設定,模型會自動識別語種。

系統僅讀取數組中的首個值。多餘值將被忽略。

點擊查看支援的語言代碼

  • fun-asr、fun-asr-2025-11-07、fun-asr-mtl、fun-asr-mtl-2025-08-25:

    • zh: 中文

    • en: 英文

    • ja: 日語

    • ko:韓語

    • vi:越南語

    • th:泰語

    • id:印尼語

    • ms:馬來語

    • tl:菲律賓語

    • hi:印地語

    • ar:阿拉伯語

    • fr:法語

    • de:德語

    • es:西班牙語

    • pt:葡萄牙語

    • ru:俄語

    • it:意大利語

    • nl:荷蘭語

    • sv:瑞典語

    • da:丹麥語

    • fi:芬蘭語

    • no:挪威語

    • el:希臘語

    • pl:波蘭語

    • cs:捷克語

    • hu:匈牙利語

    • ro:羅馬尼亞語

    • bg:保加利亞語

    • hr:克羅地亞語

    • sk:斯洛伐克語

  • fun-asr-2025-08-25:

    • zh: 中文

    • en: 英文

返回體

{
  "output": {
    "task_status": "PENDING",
    "task_id": "c2e5d63b-96e1-4607-bb91-************"
  },
  "request_id": "77ae55ae-be17-97b8-9942--************"
}

request_id string

本次調用的唯一識別碼。

output object

提交任務返回的資料。

屬性

task_id string

任務ID。該ID在查詢任務介面中作為string傳入。

task_status string

任務狀態。提交成功時返回PENDING

查詢任務介面

查詢語音辨識任務的執行情況和結果。建議輪詢調用直至任務終態。

請求體

以下為新加坡地區的配置,調用時請將"{WorkspaceId}"替換為真實的業務空間ID,各地區的配置不同。新加坡地區和北京地區的API Key不同。

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}' \
     --header "Authorization: Bearer $DASHSCOPE_API_KEY"

task_id string (必選)

重要

該參數為URL路徑參數,無請求體。

查詢任務需指定其ID,該ID為提交任務介面被調用後返回的task_id

返回體

正常樣本

{
  "request_id": "f9e1afad-94d3-997e-a83b-************",
  "output": {
    "task_id": "f86ec806-4d73-485f-a24f-************",
    "task_status": "SUCCEEDED",
    "submit_time": "2024-09-12 15:11:40.041",
    "scheduled_time": "2024-09-12 15:11:40.071",
    "end_time": "2024-09-12 15:11:40.903",
    "results": [
      {
        "file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav",
        "transcription_url": "https://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/pre/filetrans-16k/20240912/15%3A11/409a4b92-445b-4dd8-8c1d-f110954d82d8-1.json?Expires=1726211500&OSSAccessKeyId=yourOSSAccessKeyId&Signature=v5Owy5qoAfT7mzGmQgH0g8C****%3D",
        "subtask_status": "SUCCEEDED"
      }
    ],
    "task_metrics": {
      "TOTAL": 1,
      "SUCCEEDED": 1,
      "FAILED": 0
    }
  },
  "usage": {
    "duration": 9
  }
}

異常樣本

{
    "task_id": "7bac899c-06ec-4a79-8875-xxxxxxxxxxxx",
    "task_status": "SUCCEEDED",
    "submit_time": "2024-12-16 16:30:59.170",
    "scheduled_time": "2024-12-16 16:30:59.204",
    "end_time": "2024-12-16 16:31:02.375",
    "results": [
        {
            "file_url": "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/sensevoice/rich_text_exaple_1.wav",
            "code": "FILE_DOWNLOAD_FAILED",
            "message": "FILE_DOWNLOAD_FAILED",
            "subtask_status": "FAILED"
        }
    ],
    "task_metrics": {
        "TOTAL": 1,
        "SUCCEEDED": 0,
        "FAILED": 1
    }
}

request_id string

本次調用的唯一識別碼。

output object

查詢任務返回的資料。

屬性

task_id string

被查詢任務的ID。

task_status string

被查詢任務的狀態。

說明

當任務包含多個子任務時,只要存在任一子任務成功,整個任務狀態將標記為SUCCEEDED,需通過subtask_status欄位判斷具體子任務結果。

submit_time string

任務提交時間。

scheduled_time string

任務被調度執行的時間。

end_time string

任務結束時間。

results array[object]

每個待識別音頻檔案對應的子任務結果清單。

屬性

subtask_status string

子任務狀態。

file_url string

檔案轉寫任務中所處理的檔案URL。

transcription_url string

擷取識別結果對應的連結。該連結有效期間為24小時,逾時後無法查詢任務或通過先前查詢結果中的URL下載結果。

識別結果儲存為JSON檔案,您可以通過上述連結下載該檔案或直接通過HTTP請求讀取該檔案中的內容。JSON資料中各欄位含義請參見識別結果說明

code string

重要

僅當子任務失敗時返回。

子任務失敗的錯誤碼。

message string

重要

僅當子任務失敗時返回。

子任務失敗的錯誤資訊。

task_metrics object

任務整體執行情況統計。

屬性

TOTAL integer

子任務總數。

SUCCEEDED integer

成功的子任務數。

FAILED integer

失敗的子任務數。

其他介面:批量查詢任務狀態/取消任務

詳情請參見管理非同步任務:支援批量查詢24小時內提交的錄音檔案識別任務,同時支援取消PENDING(排隊)狀態的任務。

識別結果說明

識別結果儲存為JSON檔案。

點擊查看識別結果樣本

{
    "file_url":"https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav",
    "properties":{
        "audio_format":"pcm_s16le",
        "channels":[
            0
        ],
        "original_sampling_rate":16000,
        "original_duration_in_milliseconds":3834
    },
    "transcripts":[
        {
            "channel_id":0,
            "content_duration_in_milliseconds":3720,
            "text":"Hello world, 這裡是阿里巴巴語音實驗室。",
            "sentences":[
                {
                    "begin_time":100,
                    "end_time":3820,
                    "text":"Hello world, 這裡是阿里巴巴語音實驗室。",
                    "sentence_id":1,
                    "speaker_id":0, //當開啟自動說話人分離功能時才會顯示該欄位
                    "words":[
                        {
                            "begin_time":100,
                            "end_time":596,
                            "text":"Hello ",
                            "punctuation":""
                        },
                        {
                            "begin_time":596,
                            "end_time":844,
                            "text":"world",
                            "punctuation":", "
                        }
                        // 這裡省略其它內容
                    ]
                }
            ]
        }
    ]
}

需要關注的參數如下:

參數

類型

說明

audio_format

string

源檔案中音訊格式。

channels

array[integer]

源檔案中音訊音軌索引資訊,對單軌音頻返回[0],對雙軌音頻返回[0, 1],以此類推。

original_sampling_rate

integer

源檔案中音訊採樣率(Hz)。

original_duration_in_milliseconds

integer

源檔案中的原始音頻時間長度(ms)。

channel_id

integer

轉寫結果的音軌索引,以0為起始。

content_duration

integer

音軌中被判定為語音內容的時間長度(ms)。

重要

語音辨識模型服務僅對音軌中被判定為語音內容的時間長度進行語音轉寫,並據此進行計量計費,非語音內容不計量、不計費。通常情況下語音內容時間長度會短於原始音頻時間長度。由於對是否存在語音內容的判定是由AI模型給出的,可能與實際情況存在一定誤差。

transcript

string

段落層級的語音轉寫結果。

sentences

array

句子層級的語音轉寫結果。

words

array

詞層級的語音轉寫結果。

begin_time

integer

開始時間戳(ms)。

end_time

integer

結束時間戳記(ms)。

text

string

語音轉寫結果。

speaker_id

integer

當前說話人的索引,以0為起始,用於區分不同的說話人。

僅在啟用說話人分離功能時,該欄位才會顯示於識別結果中。

punctuation

string

預測出的詞之後的標點符號(如有)。

DashScope同步調用(Fun-ASR-Flash)

重要

該功能不支援SDK調用。

服務端點

新加坡

POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

調用時請將{WorkspaceId}替換為真實的Workspace ID

華北2(北京)

POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

調用時請將{WorkspaceId}替換為真實的Workspace ID

重要

阿里雲百鍊為華北2(北京)、新加坡地區推出了業務空間專屬網域名稱,能夠為推理請求提供卓越的效能和更高的穩定性,建議遷移至新網域名稱:

  • 華北2(北京)地區:從 dashscope.aliyuncs.com 遷移至 {WorkspaceId}.cn-beijing.maas.aliyuncs.com

  • 新加坡地區:從 dashscope-intl.aliyuncs.com 遷移至 {WorkspaceId}.ap-southeast-1.maas.aliyuncs.com

{WorkspaceId}需要替換為真實的Workspace ID。現有網域名稱仍可正常使用。

要求標頭

參數

類型

是否必選

說明

Authorization

string

鑒權令牌,格式為Bearer <your_api_key>,使用時將"<your_api_key>"替換為實際的API Key。

Content-Type

string

請求體的媒體類型,固定為application/json

X-DashScope-SSE

string

用於控制是否以SSE流式方式返回結果。設定為enable時開啟SSE流式返回模式,服務端會分多次返回中間識別結果和最終結果;設定為disable或不傳該參數則僅返回最終結果。

請求體

以下為新加坡地區的配置,調用時請將"{WorkspaceId}"替換為真實的業務空間ID,各地區的配置不同。新加坡地區和北京地區的API Key不同。

非流式

curl --location --request POST 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
     --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
     --header "Content-Type: application/json" \
     --header "X-DashScope-SSE: disable" \
     --data '{
    "model": "fun-asr-flash-2026-06-15",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_audio",
                        "input_audio": {
                            "data": "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav"
                        }
                    }
                ]
            }
        ]
    },
    "parameters": {
        "format": "wav",
        "sample_rate": "16000"
    }
}'

流式

curl --location --request POST 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
     --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
     --header "Content-Type: application/json" \
     --header "X-DashScope-SSE: enable" \
     --data '{
    "model": "fun-asr-flash-2026-06-15",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_audio",
                        "input_audio": {
                            "data": "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav"
                        }
                    }
                ]
            }
        ]
    },
    "parameters": {
        "format": "wav",
        "sample_rate": "16000"
    }
}'

攜帶上下文-非流式

curl --location --request POST 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
     --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
     --header "Content-Type: application/json" \
     --header "X-DashScope-SSE: disable" \
     --data '{
    "model": "fun-asr-flash-2026-06-15",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_text",
                        "text": "你好啊"
                    }
                ]
            },
            {
                "role": "assistant",
                "content": [
                    {
                        "type": "text",
                        "text": "你好啊,我是通義千問,有什麼可以協助你的?"
                    }
                ]
            },
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_audio",
                        "input_audio": {
                            "data": "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav"
                        }
                    }
                ]
            }
        ]
    },
    "parameters": {
        "format": "wav",
        "sample_rate": "16000"
    }
}'

攜帶上下文-流式

curl --location --request POST 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
     --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
     --header "Content-Type: application/json" \
     --header "X-DashScope-SSE: enable" \
     --data '{
    "model": "fun-asr-flash-2026-06-15",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_text",
                        "text": "你好啊"
                    }
                ]
            },
            {
                "role": "assistant",
                "content": [
                    {
                        "type": "text",
                        "text": "你好啊,我是通義千問,有什麼可以協助你的?"
                    }
                ]
            },
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_audio",
                        "input_audio": {
                            "data": "https://dashscope.oss-cn-beijing.aliyuncs.com/samples/audio/paraformer/hello_world_female2.wav"
                        }
                    }
                ]
            }
        ]
    },
    "parameters": {
        "format": "wav",
        "sample_rate": "16000"
    }
}'

Base64

可輸入Base64編碼資料(Data URL),格式為:data:<mediatype>;base64,<data>

  • <mediatype>:MIME類型

    因音頻格式而異,例如:

    • WAV:audio/wav

    • MP3:audio/mpeg

  • <data>:音頻轉成的Base64編碼的字串

    Base64編碼會增大體積,請控制原檔案大小,確保編碼後仍符合輸入音頻大小限制(10MB)

  • 樣本:data:audio/wav;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//PAxABQ/BXRbMPe4IQAhl9

    點擊查看範例程式碼

    import base64, pathlib
    
    # input.mp3為待識別的本地音頻檔案,請替換為自己的音頻檔案路徑,確保其符合音頻要求
    file_path = pathlib.Path("input.mp3")
    base64_str = base64.b64encode(file_path.read_bytes()).decode()
    data_uri = f"data:audio/mpeg;base64,{base64_str}"
    import java.nio.file.*;
    import java.util.Base64;
    
    public class Main {
        /**
         * filePath為待識別的本地音頻檔案,請替換為自己的音頻檔案路徑,確保其符合音頻要求
         */
        public static String toDataUrl(String filePath) throws Exception {
            byte[] bytes = Files.readAllBytes(Paths.get(filePath));
            String encoded = Base64.getEncoder().encodeToString(bytes);
            return "data:audio/mpeg;base64," + encoded;
        }
    
        public static void main(String[] args) throws Exception {
            System.out.println(toDataUrl("input.mp3"));
        }
    }
import base64, pathlib
import os
import requests

# input.wav為待識別的本地音頻檔案,請替換為自己的音頻檔案路徑,確保其符合音頻要求
file_path = pathlib.Path("input.wav")
base64_str = base64.b64encode(file_path.read_bytes()).decode()
data_uri = f"data:audio/wav;base64,{base64_str}"

# 請將"{WorkspaceId}"替換為真實的業務空間ID
url = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation"

headers = {
    "Authorization": f"Bearer {os.environ['DASHSCOPE_API_KEY']}",
    "Content-Type": "application/json",
    "X-DashScope-SSE": "disable",
}

payload = {
    "model": "fun-asr-flash-2026-06-15",
    "input": {
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_audio",
                        "input_audio": {
                            "data": data_uri,
                        },
                    }
                ],
            }
        ]
    },
    "parameters": {
        "format": "wav",
        "sample_rate": "16000",
    },
}

response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(response.json())

model string (必選)

模型名稱,固定為fun-asr-flash-2026-06-15

input object (必選)

輸入資訊。

屬性

messages array(object) (必選)

訊息列表。包含當前待識別的音頻,以及可選的對話上下文(用於提升識別效果)。

重要

上下文功能用於提升專有詞彙的識別準確率,使用方法詳見快速開始。約束:上下文訊息(input_texttext 類型)各最多 5 條,超出時保留最近的 5 條。每輪上下文文本總長度(userassistanttext 欄位長度之和)不超過 400 個字元(按字元數計算,每個字元計為 1),超出部分從末尾截斷。

重要

攜帶上下文時,messages 中的訊息順序有要求:上下文訊息必須按對話輪次排列,每輪中 userinput_text 類型)必須在對應的 assistanttext 類型)之前;包含 input_audiouser 訊息必須放在 messages 數組的最後。

屬性

role string (必選)

訊息角色。取值範圍:

  • user(必選):使用者訊息。type為input_audio時表示當前待識別的音頻;type為input_text時表示前幾輪的識別結果或領域相關的詞表(可選,上下文)。

  • assistant(可選,上下文):前幾輪大語言模型的回複內容。

content array(object) (必選)

訊息內容列表。

屬性

type string (必選)

內容類型。每個請求至少需要一條input_audio類型的訊息。取值範圍:

  • input_audio(必選):當前待識別的音頻輸入(role為user),需同時傳入input_audio對象。

  • input_text(可選,上下文):前幾輪使用者語音的識別結果或領域相關的詞表(role為user),需同時傳入text欄位。

  • text(可選,上下文):前幾輪大語言模型的回複內容(role為assistant),需同時傳入text欄位。

input_audio object (條件必選)

typeinput_audio時必填。

屬性

data string (必選)

待識別音頻資料。關於支援的音頻格式、檔案大小限制、時間長度限制等輸入要求,請參見音頻規格。支援以下兩種方式:

  • 音頻檔案URL:直接傳入可公開訪問的音頻檔案地址。

  • Base64 Data URI:採用Data URI格式傳入Base64編碼的音頻資料,值由data:{MIME_TYPE};base64,首碼與Base64編碼的音頻資料拼接而成。支援的MIME類型包括audio/wavaudio/mp3等。

樣本(URL方式):https://example.com/audio/sample.wav

樣本(Base64方式):data:audio/wav;base64,{BASE64_ENCODED_DATA}

text string (條件必選)

typeinput_text時,填入前幾輪使用者語音的識別結果或領域相關的詞表;當typetext時,填入前幾輪大語言模型的回複內容。文本按字元數計算,每個字元計為 1。每輪上下文中所有訊息的 text 欄位長度之和不超過 400 個字元,超出部分從末尾截斷。

parameters object (必選)

模型參數。

屬性

format string (必選)

音頻格式。根據實際音頻格式填寫,支援wavmp3opus等。詳情請參見音頻規格

sample_rate string (可選)

音頻採樣率,單位Hz。例如16000表示16kHz採樣率。詳情請參見音頻規格

返回體

非流式

{
    "output": {
        "sentence": {
            "begin_time": 760,
            "channel_id": 0,
            "end_time": 3800,
            "sentence_end": true,
            "sentence_id": 1,
            "text": "Hello World,這裡是阿里巴巴語音實驗室。",
            "words": [
                {"begin_time": 760, "end_time": 1040, "fixed": true, "punctuation": "", "text": "Hello"},
                {"begin_time": 1040, "end_time": 1240, "fixed": true, "punctuation": ",", "text": " World"},
                {"begin_time": 1360, "end_time": 1880, "fixed": true, "punctuation": "", "text": "這裡是"},
                {"begin_time": 1880, "end_time": 2520, "fixed": true, "punctuation": "", "text": "阿里巴巴"},
                {"begin_time": 2520, "end_time": 2840, "fixed": true, "punctuation": "", "text": "語音"},
                {"begin_time": 2840, "end_time": 3800, "fixed": true, "punctuation": "。", "text": "實驗室"}
            ]
        },
        "text": "Hello World,這裡是阿里巴巴語音實驗室。"
    },
    "usage": {
        "duration": 4
    },
    "request_id": "40e0734d-096f-9ae3-86c1-a8c013287561"
}

流式

設定X-DashScope-SSE: enable時,服務端以Server-Sent Events協議返回識別結果。SSE事件格式如下:

id:{序號}
event:result
:HTTP_STATUS/200
data:{JSON資料}

返回樣本:

id:1
event:result
:HTTP_STATUS/200
data:{"output":{"sentence":{"sentence_id":1,"sentence_end":true,"end_time":3800,"words":[{"end_time":1040,"punctuation":"","begin_time":760,"fixed":true,"text":"Hello"},{"end_time":1240,"punctuation":",","begin_time":1040,"fixed":true,"text":" World"},{"end_time":1880,"punctuation":"","begin_time":1360,"fixed":true,"text":"這裡是"},{"end_time":2520,"punctuation":"","begin_time":1880,"fixed":true,"text":"阿里巴巴"},{"end_time":2840,"punctuation":"","begin_time":2520,"fixed":true,"text":"語音"},{"end_time":3800,"punctuation":"。","begin_time":2840,"fixed":true,"text":"實驗室"}],"begin_time":760,"text":"Hello World,這裡是阿里巴巴語音實驗室。","channel_id":0},"text":"Hello World,這裡是阿里巴巴語音實驗室。"},"usage":{"duration":4},"request_id":"fc1582e4-935c-9fc2-a482-a98bf43daa69"}

request_id string

本次請求的唯一標識。

output object

輸出結果。

屬性

text string

當前累積的完整識別文本。

sentence object

當前句子的詳細資料。

屬性

sentence_id integer

句子編號,從1開始。

sentence_end boolean

是否為該句的最終結果。為true時表示該句識別完成。

begin_time integer

句子開始時間,單位毫秒。

end_time integer

句子結束時間,單位毫秒。僅在sentence_endtrue時返回。

text string

當前句子的識別文本。

channel_id integer

聲道編號,從0開始。

words array

詞層級時間戳記列表。

屬性

text string

詞文本。

begin_time integer

詞開始時間,單位毫秒。

end_time integer

詞結束時間,單位毫秒。

punctuation string

詞後的標點符號。無標點時為空白字串。

fixed boolean

詞是否已穩定。false表示後續事件中該詞的時間戳記可能調整。

usage object

用量資訊。僅在sentence_endtrue時返回。

屬性

duration integer

已處理的音頻時間長度,單位秒。

SSE 流式結果處理邏輯

在流式模式下,用戶端需關注以下處理要點:

  1. 每收到一個SSE事件,解析data欄位中的JSON。

  2. 通過output.sentence.sentence_end判斷當前句子是否結束:當該值為true時,該句識別完成,詞級時間戳記已穩定,可作為最終結果使用;當該值為false時,識別仍在進行中,文本和時間戳記可能在後續事件中更新。

  3. usage資訊僅在句子結束事件中返回,可用於計量音頻處理時間長度。