ELSA SpeakELSA Speak

ตัวอย่างการใช้งาน API

Updated June 16, 2026·56 views

Automatically translated. View the original in English.

ตัวอย่างการใช้งาน API

Scripted Requests

ด้านล่างนี้คือตัวอย่างบางส่วนที่แสดงการใช้งาน scripted APIs

Score_audio endpoint

การสาธิตนี้จะดำเนินการบน command line โดยใช้ระบบที่เข้ากันได้กับ Linux ผ่านคำสั่ง cURL

คำสั่ง cURL โดยใช้พารามิเตอร์ audio_path

ในตัวอย่างนี้ เราจะใช้ประโยค "When the sunlight strikes raindrops in the air, they act like a prism and form a rainbow." โดยมีไฟล์เสียงอยู่ที่ URL สาธารณะนี้ [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>"

คำสั่ง cURL โดยใช้พารามิเตอร์ audio_file

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" เพื่อรับผลลัพธ์ที่มีรายละเอียดมากขึ้นหรือน้อยลงได้

ตัวอย่างการรองรับ Multiple-choice

โดยใช้ endpoint และพารามิเตอร์เดียวกันกับข้างต้น เราสามารถให้คะแนนแบบฝึกหัดแบบ multiple-choice ได้ด้วย โดย ELSA engine จะ: 1) เลือกคำ/ประโยคที่ตรงกับข้อมูลของผู้ใช้มากที่สุด; b) ให้คะแนนประโยคนั้นเหมือนกรณีประโยคเดี่ยว ในการทำ multiple-choice เราจะส่งรายการประโยคที่เป็นไปได้ในฟิลด์ sentence:

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

ไม่มีการจำกัดจำนวนประโยคที่คุณสามารถส่งได้

นี่คือวิธีส่งรายการในคำสั่ง curl:

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

Unscripted Requests

ต่อไปนี้คือตัวอย่างการใช้งาน unscripted APIs บางส่วน

Score_audio_plus endpoint

ในการเรียกใช้งาน ELSA API เราสามารถใช้คำสั่ง "curl" ใน command line ที่เข้ากันได้กับ Linux ใดก็ได้

คำสั่ง cURL โดยใช้พารามิเตอร์ audio_file

ตัวอย่างต่อไปนี้จะคืนค่าลิงก์สำหรับดาวน์โหลดไฟล์ json ผลลัพธ์เมื่อเรียกใช้ด้วยไฟล์เสียงในเครื่อง (อย่าลืมใส่ "@" ก่อน path)

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 endpoint

ตัวอย่างการใช้งาน ASR transcript และการจัดแนวเวลาระดับคำ:

curl -XPOST -s https://api.elsanow.io/api/v1/asr -F "audio=@<path_to_your_file.wav>" --header "Authorization: ELSA <API_token>"
การดึงข้อมูลแบบ Asynchronous

ตัวอย่างการใช้งานแบบ asynchronous เราเริ่มต้นด้วยการเรียก 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>"}
Result endpoint

ในการดึงไฟล์ผลลัพธ์ (ไม่ว่าจะเป็นลิงก์ดาวน์โหลดหรือโครงสร้าง json) ให้เรียก result endpoint

ดึงผลลัพธ์หนึ่งรายการ โดยรับลิงก์ดาวน์โหลด:
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>"
Audio endpoint

ในการดึงไฟล์เสียง:

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.