Metadata-Version: 2.4
Name: speechline-sdk
Version: 2612.0
Summary: Speechline's API: transcription, translation and speech, live and from files
License-Expression: Apache-2.0
Project-URL: Homepage, https://www.speechline.ai
Project-URL: Documentation, https://www.speechline.ai/docs
Project-URL: Repository, https://github.com/speechline-dev/speechline-python
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: protobuf<8,>=7.35.1
Requires-Dist: websockets>=15.0.1
Dynamic: license-file

# speechline-sdk

Speechline's API from Python 3.10 or later: transcription, translation and speech, live and from files, over REST
and the WebSocket.

```sh
pip install speechline-sdk
export SPEECHLINE_API_KEY=lp_...    # the app's Keys page: https://app.speechline.ai
```

The source, a tag a release: https://github.com/speechline-dev/speechline-python
(`pip install git+https://github.com/speechline-dev/speechline-python@vVERSION`).

## Transcribe a file

```python
from speechline import Client

client = Client()
media = client.upload(open("talk.wav", "rb").read(), filename="talk.wav", content_type="audio/wav")
job = client.create_job(template_id="file-transcription",
                        params=[{"name": "media", "value": {"string_value": media.id}}])
end = client.watch_job(job.run.id, timeout=600).wait()
print(client.download(end.run_id, "subtitles.srt").decode())
```

`file-translation` takes `targets` too (`{"list_value": {"values": ["de", "uk"]}}`); `file-speech` takes `text`.

## Live

A session streams audio in and results out as they come: 16 kHz mono PCM (s16le) by default, or the rate given in
`format`.

```python
from speechline import Client, frames, stream_pcm, translation_of

client = Client()
targets = {"name": "targets", "value": {"listValue": {"values": ["de"]}}}
with client.session(open={"templateId": "stream-translation", "params": [targets]}) as s:
    s.ready.result(10)
    stream_pcm(s, pcm, pace="realtime")    # a microphone's chunks: s.send(chunk)
    s.finish(60)
    for e in s.events():
        t = frames.Transcript()
        if e.kind == "output.transcript" and e.data.Unpack(t) and t.final:
            tr = translation_of(t)         # None: the transcript itself
            print(f"{tr['target']}: {tr['text']}" if tr else t.text)
```

`stream-transcription` transcribes alone; `stream-speech` speaks the text you send (`s.send_text(text)`,
`audio_of(e)` for the audio, `write_wav(path, chunks)`).

## A pipeline of your own

Any graph of the elements, in one line:

```python
s = client.session(dsl="input source=client ! queue policy=block ! asr ! translate targets=[de] mode=final ! "
                       "tts targets=[de] ! output to=client")
```

## Errors

A refused call raises `PipelineError`: `code_name` and `reason` (branch on the reason: `no_key`, `bad_key`,
`scope`, ...), and a message for people.

The API: https://www.speechline.ai/docs. Licence: Apache-2.0.
