Start with the API

The API is at https://api.speechline.ai. These examples use curl and a shell; any HTTP client works the same way.

No key yet? Create an account, then open Keys.

1. A key and the API

Create an API key on the app's Keys page (it is shown once). Every call is a POST of JSON to the method's path, with the key as a bearer token.

export API=https://api.speechline.ai
export KEY=lp_...   # your API key (the app's Keys page)
call() {
  curl --fail-with-body -sS "$API/lerna.pipeline.v1.$1" -H "Authorization: Bearer $KEY" \
    -H 'Content-Type: application/json' --data-binary "$2" && echo
}
call PipelineService/GetInfo '{}'

2. Upload a file

Audio or video, as the request's body; the answer names the upload (med_...).

MEDIA=$(curl --fail-with-body -sS "$API/v1/media?filename=talk.wav" \
  -H "Authorization: Bearer $KEY" -H 'Content-Type: audio/wav' --data-binary @talk.wav \
  | sed -nE 's/.*"id":"(med_[a-z2-7]{24})".*/\1/p')
[ -n "$MEDIA" ] || echo "the upload was refused (its answer is above)"

3. Transcribe it

A job from the file-transcription template, then wait for it to end. Telling speakers apart (diarization) is off unless set to true (this example says false); it works on the speakers' voices, which can be biometric data under the GDPR: turn it on only with a lawful basis from the speakers (see AI transparency).

RUN=$(call JobService/CreateJob "{\"templateId\": \"file-transcription\", \"params\": [
  {\"name\": \"media\", \"value\": {\"stringValue\": \"$MEDIA\"}},
  {\"name\": \"diarization\", \"value\": {\"boolValue\": false}}]}" \
  | sed -nE 's/.*"id":"(run_[a-z2-7]{24})".*/\1/p')
[ -n "$RUN" ] || echo "the job was refused (its answer is above)"
until [ -z "$RUN" ] || call JobService/GetJob "{\"jobId\": \"$RUN\"}" \
  | grep -qE '"state":"RUN_STATE_(DONE|FAILED|CANCELLED)"'; do sleep 1; done

4. Download the results

The transcript as JSON, and subtitles as SRT and VTT.

for f in transcript.json subtitles.srt subtitles.vtt; do
  curl --fail-with-body -sS -o "$f" "$API/v1/runs/$RUN/artifacts/$f" -H "Authorization: Bearer $KEY"
done

5. Delete them

Uploads and results are kept for a time (your retention settings); delete them once you have the results.

call MediaService/DeleteMedia "{\"mediaId\": \"$MEDIA\"}"
call RunService/DeleteRun "{\"runId\": \"$RUN\"}"

Translate a file

The file-translation template: the transcript, its translations and subtitles in every target language.

call JobService/CreateJob "{\"templateId\": \"file-translation\", \"params\": [
  {\"name\": \"media\", \"value\": {\"stringValue\": \"$MEDIA\"}},
  {\"name\": \"targets\", \"value\": {\"listValue\": {\"values\": [\"de\", \"uk\"]}}}]}"

Speak a text

The file-speech template: a text, paragraph by paragraph, to WAV and M4A.

call JobService/CreateJob '{"templateId": "file-speech", "params": [
  {"name": "text", "value": {"stringValue": "Hello from Speechline.\n\nA second paragraph."}},
  {"name": "language", "value": {"stringValue": "en"}}]}'
# then, once DONE: the artifacts speech.wav and speech.m4a

Errors

A refused call answers an HTTP error with this JSON; branch on the reason, never on the message.

{"code": 5, "status": "NOT_FOUND", "message": "...",
 "trailers": {"lerna-error-reason": "unknown_run"}}

Live sessions and the SDKs

Live transcription, translation and speech over the WebSocket, and the SDKs for TypeScript and Python, are on their way to the public API. Until then, ask us for early access.