Audio Conversion API
Convert audio between any of 23 supported formats — MP3, WAV, OGG, AAC, FLAC, M4A, WMA, OPUS, AIFF, AMR, AU, CAF, AC3, DTS, GSM, IRCAM, MP2, TTA, VOC, W64, WV, SPX, and RM. Like video, this is an async, submit-then-poll endpoint rather than one blocking request — same ffmpeg engine behind TransConvert's website converter.
curl -X POST \ .../api/v1/convert-async.php \ -H "Authorization: Bearer ..." \ -F "category=audio" \ -F "target=MP3" \ -F "file=@track.wav" # { "job_id": "job_...", "status": "queued" }
การแปลงวิดีโอและเสียงอาจใช้เวลาหลายนาที ซึ่งนานเกินกว่าจะเปิดค้างคำขอแบบซิงโครนัสเดียวไว้ได้ — จึงใช้รูปแบบส่งงานแล้วตรวจสอบสถานะแทนเอนด์พอยต์ด้านบน ส่งไฟล์ไป จะได้ job_id กลับมาทันที จากนั้นตรวจสอบสถานะจนกว่าจะเสร็จ
ส่งงาน
https://transconvert.com/api/v1/convert-async.php
| Field | Description |
|---|---|
Authorization | Required. "Bearer tc_live_...". |
category | Set to "audio". |
target | Required. Output format code: "MP3", "WAV", "OGG", "AAC", "FLAC", "M4A", "WMA", "OPUS", "AIFF", "AMR", "AU", "CAF", "AC3", "DTS", "GSM", "IRCAM", "MP2", "TTA", "VOC", "W64", "WV", "SPX", or "RM". |
file | Required. The audio file. |
curl -X POST \ https://transconvert.com/api/v1/convert-async.php \ -H "Authorization: Bearer tc_live_your_key_here" \ -F "category=audio" \ -F "target=MP3" \ -F "file=@track.wav" \ -o output.mp3
<?php $ch = curl_init('https://transconvert.com/api/v1/convert-async.php'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer tc_live_your_key_here'], CURLOPT_POSTFIELDS => [ 'category' => 'audio', 'target' => 'MP3', 'file' => new CURLFile('track.wav'), ], ]); $response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($status === 200) { file_put_contents('output.mp3', $response); } else { $error = json_decode($response, true); echo $error['error']['message']; }
const form = new FormData(); form.append('category', 'audio'); form.append('target', 'MP3'); form.append('file', new Blob([fs.readFileSync('track.wav')]), 'track.wav'); const res = await fetch('https://transconvert.com/api/v1/convert-async.php', { method: 'POST', headers: { Authorization: 'Bearer tc_live_your_key_here' }, body: form, }); if (res.ok) { fs.writeFileSync('output.mp3', Buffer.from(await res.arrayBuffer())); } else { const { error } = await res.json(); console.error(error.message); }
import requests with open('track.wav', 'rb') as f: response = requests.post( 'https://transconvert.com/api/v1/convert-async.php', headers={'Authorization': 'Bearer tc_live_your_key_here'}, data={'category': 'audio', 'target': 'MP3'}, files={'file': f}, ) if response.status_code == 200: with open('output.mp3', 'wb') as out: out.write(response.content) else: print(response.json()['error']['message'])
# gem install multipart-post require 'net/http' require 'net/http/post/multipart' url = URI('https://transconvert.com/api/v1/convert-async.php') File.open('track.wav') do |file| req = Net::HTTP::Post::Multipart.new url, 'category' => 'audio', 'target' => 'MP3', 'file' => UploadIO.new(file, 'application/octet-stream', 'track.wav') req['Authorization'] = 'Bearer tc_live_your_key_here' res = Net::HTTP.start(url.host, url.port, use_ssl: true) do |http| http.request(req) end if res.code == '200' File.write('output.mp3', res.body) else puts JSON.parse(res.body)['error']['message'] end end
// Gradle: implementation("com.squareup.okhttp3:okhttp:4.+") OkHttpClient client = new OkHttpClient(); RequestBody body = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("category", "audio") .addFormDataPart("target", "MP3") .addFormDataPart("file", "track.wav", RequestBody.create(new File("track.wav"), MediaType.parse("application/octet-stream"))) .build(); Request request = new Request.Builder() .url("https://transconvert.com/api/v1/convert-async.php") .header("Authorization", "Bearer tc_live_your_key_here") .post(body) .build(); try (Response response = client.newCall(request).execute()) { if (response.isSuccessful()) { Files.write(Paths.get("output.mp3"), response.body().bytes()); } else { System.err.println(response.body().string()); } }
ตรวจสอบสถานะ
ตรวจสอบทุก ๆ 2-3 วินาทีด้วย job_id ที่ได้รับกลับมา "status" มีค่าใดค่าหนึ่งจาก queued, processing, completed หรือ failed
https://transconvert.com/api/v1/job-status.php?job_id=job_...
curl -H "Authorization: Bearer tc_live_your_key_here" \ https://transconvert.com/api/v1/job-status.php?job_id=job_...
ดาวน์โหลดผลลัพธ์
เมื่อ status เป็น "completed" การตอบกลับจะมี download_url ซึ่งคือ URL ตรวจสอบสถานะเดิมที่เพิ่ม &download=1 ต่อท้าย การเรียกใช้ URL นี้จะสตรีมไฟล์ที่แปลงแล้วกลับมาโดยตรง ใช้ส่วนหัวเดียวกับเอนด์พอยต์อื่น ๆ ในหน้านี้ ผลลัพธ์จะถูกลบทันทีที่มีการดาวน์โหลด หรือถูกลบโดยอัตโนมัติหลังช่วงเวลาจัดเก็บสั้น ๆ หากไม่เคยถูกดาวน์โหลดเลย
scheduleผลลัพธ์ของงานจะถูกลบทันทีหลังดาวน์โหลด หรือถูกลบโดยอัตโนมัติหลังช่วงเวลาจัดเก็บสั้น ๆ หากไม่เคยถูกดาวน์โหลด — กรุณาดาวน์โหลดให้ทันเวลา
ข้อผิดพลาด
ทุกความล้มเหลวจะส่งกลับเป็นซองข้อผิดพลาด JSON ที่มี "code" ให้โค้ดของคุณใช้แยกกรณีได้ พร้อม "message" ที่มนุษย์อ่านเข้าใจ บางข้อผิดพลาดมีฟิลด์เพิ่มเติม (เช่น quota_exceeded จะมี "limit" และ "used")
| Status & code | When it happens |
|---|---|
401 missing_key | ไม่มีการส่งส่วนหัว Authorization มา |
401 invalid_key | คีย์นี้ไม่มีอยู่จริง หรือถูกเพิกถอนแล้ว |
403 account_suspended | บัญชีที่เป็นเจ้าของคีย์นี้ถูกระงับ |
403 plan_required | บัญชีนี้อยู่ในแพ็กเกจ Free — การใช้งาน API ต้องมี Basic, Lite, Pro หรือ Team |
400 invalid_category | "category" ไม่ใช่ "image" หรือ "document" |
400 invalid_target | "target" ไม่ใช่ฟอร์แมตผลลัพธ์ที่รองรับสำหรับหมวดหมู่นั้น |
400 no_file | ไม่มีการส่งไฟล์มา หรือการอัปโหลดล้มเหลว — ฟิลด์ต้องตั้งชื่อว่า "file" |
413 file_too_large | ไฟล์มีขนาดเกินขีดจำกัดการอัปโหลดสูงสุดของแพ็กเกจของคุณ |
429 quota_exceeded | โควตานาทีการแปลงรายเดือนของแพ็กเกจถูกใช้จนหมดแล้ว จะรีเซ็ตเมื่อเริ่มเดือนปฏิทินถัดไป |
429 concurrency_limit | มีการแปลงไฟล์ทำงานพร้อมกันมากเกินไปสำหรับบัญชีนี้ (ใช้ร่วมกับเว็บไซต์) — รอให้งานหนึ่งเสร็จก่อนแล้วลองใหม่ |
404 job_not_found | ไม่มีงานที่มี id นี้อยู่ในบัญชีนี้ (ข้อความเดียวกันนี้จะถูกส่งกลับสำหรับ job_id ของบัญชีอื่นด้วย — จะไม่มีการเปิดเผยว่ามีอยู่จริงหรือไม่) |
410 result_gone | งานเสร็จสิ้นแล้ว แต่ผลลัพธ์ถูกลบไปแล้ว (ผลลัพธ์จะถูกลบทันทีหลังดาวน์โหลด หรือโดยอัตโนมัติหลังช่วงเวลาจัดเก็บสั้น ๆ) |
400/415/422/500/503 conversion_failed | ไฟล์นี้ไม่สามารถแปลงได้ — "message" อธิบายสาเหตุ รหัสสถานะจะต่างกันไปตามสาเหตุ: 400/415/422 หมายความว่าไฟล์หรือ target นี้จะไม่สำเร็จไม่ว่าจะลองกี่ครั้งก็ตาม; 500/503 หมายถึงปัญหาฝั่งเซิร์ฟเวอร์ และ 503 โดยเฉพาะคุ้มค่าที่จะลองใหม่อีกครั้งในเวลาสั้นๆ |
Supported formats
MP3, WAV, OGG, AAC, FLAC, M4A, WMA, OPUS, AIFF, AMR, AU, CAF, AC3, DTS, GSM, IRCAM, MP2, TTA, VOC, W64, WV, SPX, RM