Version 0.3.0. These files are the code that will be published to npm and PyPI, from the same source as the Go, Ruby, PHP and Dart clients. Until that release, download the file below. npm still has the older 0.1.0 (it lacks lint(), status(), test outcomes and automatic retries); PyPI has no TonePerfect package yet, so a pip install toneperfect today would not install ours. No SDK is needed at all: the quickstart makes the same call with any HTTP client.
Python
One module, standard library only, Python 3.9+. Files: toneperfect.py · example script · MIT licence.
curl -O https://api.toneperfect.app/sdk/python/toneperfect.py # drop it next to your code
curl -o hello.ogg https://api.toneperfect.app/capsule/speech-zh-nihao.ogg
export TONEPERFECT_API_KEY="tp_test_..." # a test key: fixed example results, no creditsfrom toneperfect import TonePerfect
client = TonePerfect() # reads TONEPERFECT_API_KEY
result = client.assess("hello.ogg", text="你好", language="zh-CN")
print(result.assessable, result.overall, result.billing.credits)
for word in result.words:
for phone in word.phones:
print(word.word, phone.dimension, phone.expected, phone.heard, phone.score, phone.decision)assess() needs language and returns an Assessment: assessable, reason, overall, scores, words (each with word, score, timings, decision, pinyin and phones: dimension, expected, heard, score, decision), billing (credits, balances, source), warnings, engine, id, replayed, test, and data, the untouched JSON. The same attributes read the compact schema (compact=True).
Node.js
Plain JavaScript, ESM and CommonJS, TypeScript types, no build step, Node 18+. Files: index.cjs · index.mjs · index.d.ts · index.d.mts · package.json · rubric.cjs · bin/toneperfect-lint.cjs · example script · MIT licence.
mkdir -p node_modules/toneperfect/bin && cd node_modules/toneperfect
for f in index.cjs index.mjs index.d.ts index.d.mts package.json rubric.cjs rubric.d.ts LICENSE bin/toneperfect-lint.cjs; do
curl -s -o "$f" https://api.toneperfect.app/sdk/node/$f
done
cd ../..import { TonePerfect } from 'toneperfect';
const client = new TonePerfect(); // reads TONEPERFECT_API_KEY
const result = await client.assess('hello.ogg', { text: '你好', language: 'zh-CN' });
console.log(result.assessable, result.overall, result.billing.credits);
for (const word of result.words) {
for (const phone of word.phones) console.log(word.word, phone.dimension, phone.expected, phone.heard, phone.score, phone.decision);
}audio is a file path, URL, Buffer, Uint8Array, ArrayBuffer or Blob. The getters match the Python client in camelCase (startMs, modelVersion, billing.balanceCredits).
Errors and safe retries
Every failure is a TonePerfectError with the API's code, its message, status and request id, as one of AuthenticationError (401), PaymentRequiredError (402, with a billing_url / billingUrl to start or renew a plan), RateLimitError (429), ValidationError (other 4xx), ServerError (5xx) and APIConnectionError (timeout or network failure).
Each assess() call makes one Idempotency-Key and keeps it for its own retries: a failure that stored nothing (busy, rate limit, upload timeout, engine_unavailable, a proxy 502/504, a timeout) is retried up to max_retries / maxRetries times (2 by default), honouring Retry-After. A result that finished after you stopped waiting comes back on that retry and is charged once. retryable on the final error says the same key may be tried again later; needs_new_key / needsNewKey says the failure is stored under the key (invalid_assessment) and a new attempt needs a new key. To resend the same recording after a crash, pass your own key (new_idempotency_key() / newIdempotencyKey()). Timeouts: timeout (seconds) / timeoutMs, 60 s by default.
Test keys
A test key (tp_test_…) returns fixed example results and never spends credits. Rehearse each failure with test_outcome / testOutcome: subscription_required, insufficient_credits, rate_limit, account_busy, engine_unavailable, invalid_assessment or unassessable.
from toneperfect import TonePerfect, PaymentRequiredError
try:
TonePerfect().assess("hello.ogg", text="你好", language="zh-CN", test_outcome="subscription_required")
except PaymentRequiredError as error:
print(error.code, "->", error.billing_url)What both clients do
| Method | Endpoint | Notes |
|---|---|---|
assess(audio, text, language, …) | POST /v1/assess | language required. Optional pinyin, task, compact, test_outcome, your own idempotency key, file name and type (from the extension by default). |
capabilities() | GET /v1/capabilities | No key needed. Languages with status (all experimental today), dimensions, limits, model_version. |
lint(text, language) | POST /v1/lint | Free, no key: check a reference text before anyone records it. Command line: python -m toneperfect lint or toneperfect-lint. |
status() | GET /v1/status | The synthetic engine probe. |
Accounts, API keys, usage and billing are managed in the dashboard and are deliberately not wrapped: those routes are session-based. Keep your key on your server; browser and mobile apps should call your own backend. Configuration: api_key / apiKey (default TONEPERFECT_API_KEY), base_url / baseUrl (default TONEPERFECT_BASE_URL, else this site), and extra headers such as TonePerfect-Fallback: off.
What the numbers mean
Grades are 0–100 display scores calibrated per language against native-speaker references; they are not accuracy percentages and not comparable across vendors. Correction decisions are separate from grades: show the grade, act on the decision. Every language pack is currently labelled experimental. The full account is on the methodology page.
Other languages
Go, Ruby, PHP and Dart clients with the same design and version are prepared for release on their registries. Until then, any HTTP client works: the API is one multipart POST (see the quickstart).