Generate a sound effect from a text prompt with a caller-specified duration. Returns 202 Accepted with a task_id; poll GET /v1/tasks/:task_id until the task reaches a terminal status.
POST/v1/text-to-sfxmultipart/form-data
curl -X POST https://api.sonilo.com/v1/text-to-sfx \ -H "Authorization: Bearer sk_your_api_key" \ -F "prompt=heavy rain on a tin roof with distant thunder" \ -F "duration=10"# => {"task_id": "9f5f2f7e-...", "status": "processing"}curl https://api.sonilo.com/v1/tasks/9f5f2f7e-... \ -H "Authorization: Bearer sk_your_api_key"# poll until "status" is "succeeded" or "failed"
import timeimport requestsheaders = {"Authorization": "Bearer sk_your_api_key"}submit = requests.post( "https://api.sonilo.com/v1/text-to-sfx", headers=headers, files={ "prompt": (None, "heavy rain on a tin roof with distant thunder"), "duration": (None, "10"), }, timeout=30,)submit.raise_for_status()task_id = submit.json()["task_id"]while True: task = requests.get( f"https://api.sonilo.com/v1/tasks/{task_id}", headers=headers, timeout=30, ).json() if task["status"] != "processing": break time.sleep(3)if task["status"] == "succeeded": print(task["audio"]["url"])else: print(task["error"])
const headers = { Authorization: "Bearer sk_your_api_key" };const form = new FormData();form.append("prompt", "heavy rain on a tin roof with distant thunder");form.append("duration", "10");const submit = await fetch("https://api.sonilo.com/v1/text-to-sfx", { method: "POST", headers, body: form,});const { task_id } = await submit.json();let task;do { await new Promise((r) => setTimeout(r, 3000)); task = await ( await fetch(`https://api.sonilo.com/v1/tasks/${task_id}`, { headers }) ).json();} while (task.status === "processing");if (task.status === "succeeded") { console.log(task.audio.url);} else { console.log(task.error);}