ELSA SpeakELSA Speak

API 使用範例

Updated June 16, 2026·56 views

Automatically translated. View the original in English.

API 使用範例

腳本式請求

以下是一些展示腳本式 API 使用方式的範例。

Score_audio 端點

此示範將透過 cURL 指令,在 Linux 相容系統的命令列上執行。

使用 audio_path 參數的 cURL 指令

在此範例中,我們將使用句子「When the sunlight strikes raindrops in the air, they act like a prism and form a rainbow.」,音訊可在此公開網址取得 [https://elsa-api-docs.s3-eu-west-1.amazonaws.com/api\_samples/rainbow.wav]{{LINK0}}

curl -XPOST -s https://api.elsanow.io/api/v2/score_audio -F "api_plan=premium" -F "audio_path=https://elsa-api-docs.s3-eu-west-1.amazonaws.com/api_samples/rainbow.wav" -F sentence="When the sunlight strikes raindrops in the air, they act like a prism and form a rainbow" --header "Authorization: ELSA <API_token>"

使用 audio_file 參數的 cURL 指令

curl -XPOST -s https://api.elsanow.io/api/v2/score_audio -F "api_plan=premium" -F "audio_file=@<path_to_the_file>/rainbow.wav" -F sentence="When the sunlight strikes raindrops in the air, they act like a prism and form a rainbow" --header "Authorization: ELSA <API_token>"

您可以更改「api_plan」參數以獲取更多或更少的詳細結果。

多選題支援範例

使用與上述相同的端點和參數,我們也可以對多選題練習進行評分,ELSA 引擎將會:1) 選擇最符合使用者輸入的單字/句子;b) 如同單一句子的情況對該句子進行評分。若要執行多選題,我們將在 sentence 欄位中傳送一組可能的句子:

sentence: ["sentence 0", "sentence 1"]

您可以傳送的句子數量沒有限制。

以下是在 curl 指令中傳送清單的方法:

sentence="[\"sentence 0\",\"sentence 1\"]"

非腳本式請求

以下是一些非腳本式 API 使用方式的範例。

Score_audio_plus 端點

若要實作對 ELSA API 的呼叫,我們可以在任何 Linux 相容的命令列中使用「curl」指令。

使用 audio_file 參數的 cURL 指令

以下範例在使用本機音訊檔案呼叫時,將回傳用於下載結果 json 的連結(請勿忘記在路徑前加上「@」)。

curl -XPOST -s https://api.elsanow.io/api/v1/score_audio_plus -F "api_plan=premium" -F "audio_file=@<path_to_your_file.wav>" --header "Authorization: ELSA <API_token>"

如果您希望直接收到 json 作為呼叫的回應,請執行:

 curl -XPOST -s https://api.elsanow.io/api/v1/score_audio_plus -F "api_plan=premium" -F "return_json=true" -F "audio_file=@<path_to_your_file.wav>" --header "Authorization: ELSA <API_token>"

ASR 端點

ASR 轉錄及單字級時間對齊的使用範例:

curl -XPOST -s https://api.elsanow.io/api/v1/asr -F "audio=@<path_to_your_file.wav>" --header "Authorization: ELSA <API_token>"
非同步功能擷取

非同步使用方式的範例。我們首先使用音訊檔案呼叫 API,並從中取得 stream_id。

curl -XPOST -s https://api.elsanow.io/api/v1/score_audio_plus -F "api_plan=premium" -F "audio_file=@<path_to_your_file.wav>" --header "Authorization: ELSA <API_token>" -F "sync=false" 

以下是結果範例:

{"stream_id":"<unique_stream_id>"}
結果端點

若要擷取結果檔案(以下載連結或 json 結構的形式),請呼叫結果端點。

擷取單一結果,取得下載連結:
curl -XGET "https://api.elsanow.io/result?stream_id=<unique_stream_id>" --header "Authorization: ELSA <API_token>"

以 json 格式擷取單一結果

擷取單一結果:

curl -XGET "https://api.elsanow.io/result?stream_id=<unique_stream_id>&return_json=true" --header "Authorization: ELSA <API_token>"

同時擷取多個結果(此選項不允許在呼叫中回傳 json)

curl -XGET "https://api.elsanow.io/result?stream_id=<unique_stream_id>&stream_id=<unique_stream_id>" --header "Authorization: ELSA <API_token>"
音訊端點

若要擷取音訊檔案:

curl -XGET "https://api.elsanow.io/audio?stream_id=<unique_stream_id>" --header "Authorization: ELSA <API_token>"

Was this article helpful?

Or open the chat in the corner to ask follow-up questions.