satham 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ dist/
satham-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
satham-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,219 @@
1
+ Metadata-Version: 2.4
2
+ Name: satham
3
+ Version: 0.1.0
4
+ Summary: Async Python client for Satham's realtime speech-to-speech API
5
+ Project-URL: Homepage, https://satham.ai
6
+ Author: Satham
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: hindi,indian-languages,realtime,satham,speech,speech-to-speech,tamil,telugu,voice-agent,websocket
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Framework :: AsyncIO
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: websockets<18,>=13.1
24
+ Description-Content-Type: text/markdown
25
+
26
+ # satham
27
+
28
+ An async Python client for Satham's realtime speech-to-speech API. Your agent brings its own
29
+ instructions, greeting and tools; you connect to your Satham endpoint with your API key, stream the
30
+ caller's audio in and the agent's audio out, follow transcripts, interruptions and language changes,
31
+ answer tool calls, and change any of the call's controls while it runs.
32
+
33
+ Python 3.11+. One dependency: `websockets`.
34
+
35
+ ```sh
36
+ pip install satham
37
+ ```
38
+
39
+ Framework adapters: [`livekit-plugins-satham`](https://pypi.org/project/livekit-plugins-satham/) for
40
+ LiveKit Agents and [`pipecat-satham`](https://pypi.org/project/pipecat-satham/) for Pipecat.
41
+
42
+ ## A call
43
+
44
+ You pass your Satham endpoint and API key (or set `SATHAM_URL` and `SATHAM_API_KEY`); there is no
45
+ default server.
46
+
47
+ ```python
48
+ import asyncio
49
+ import os
50
+
51
+ import satham
52
+
53
+ ROLE = "You are Asha, who books site visits for Example Homes. Keep every reply short."
54
+
55
+
56
+ async def main() -> None:
57
+ async with satham.connect(
58
+ os.environ["SATHAM_URL"], # your Satham endpoint, wss://... or https://...
59
+ os.environ["SATHAM_API_KEY"],
60
+ instructions=ROLE, # the agent's role: your prompt
61
+ greeting="Hello, this is Asha from Example Homes. Is this a good time?",
62
+ language="en", # or "auto"; the call can follow the caller into another language
63
+ language_switch="auto",
64
+ sample_rate=16_000, # the caller audio you send: 16-bit mono PCM
65
+ ) as call:
66
+ asyncio.create_task(stream_microphone(call)) # await call.send_audio(pcm) per packet
67
+ async for event in call:
68
+ match event:
69
+ case satham.ResponseAudio():
70
+ speaker.write(event.data) # PCM in call.output_audio's format
71
+ case satham.SpeechStarted() | satham.ResponseInterrupted():
72
+ speaker.clear() # the caller is talking: stop at once
73
+ case satham.TranscriptFinal():
74
+ print("caller:", event.text, event.language)
75
+ case satham.ResponseDone():
76
+ print("agent:", event.text)
77
+ case satham.SessionUpdated():
78
+ print("now in", event.language, "because of the", event.reason)
79
+
80
+
81
+ asyncio.run(main())
82
+ ```
83
+
84
+ Without a `greeting` the caller speaks first. `connect()` raises `AuthenticationError`,
85
+ `ServerBusyError`, `InvalidRequestError` (a refused setting) or `SathamError` (connection failures
86
+ and timeouts; `.code` says which). A bad value fails in the client with `ValueError` before anything
87
+ is sent.
88
+
89
+ During the call, `await call.update(...)` changes any control (the same names as `connect`; only what
90
+ you pass is sent, and `instructions` can change too), `call.commit()` ends the caller's turn now
91
+ (push-to-talk), `call.cancel()` stops the reply, and `call.close()` ends the call. `call.language`
92
+ follows every language change.
93
+
94
+ Replies on demand: `await call.create_response(instructions=None)` asks for a reply now (to open the
95
+ call, or after a quiet spell; `instructions` guide that reply alone), and `await call.say(text)` has
96
+ the agent say fixed words in its voice. While a reply is under way, or the caller is speaking, the
97
+ server answers with a non-fatal `response_in_progress` error.
98
+
99
+ ## Controls
100
+
101
+ Every keyword of `connect()` and `update()` besides the URL, key and audio format is a control
102
+ (`satham.SessionControls`, a `TypedDict`). OpenAI's names are used where LiveKit's OpenAI realtime
103
+ plugin has one; groups (`turn_detection`, `input_audio_noise_reduction`, `input_audio_transcription`,
104
+ `phrasing`) are dicts of the keys shown. A control you leave out is not sent, so the server's default
105
+ holds. Values are checked against the ranges below, or against your server's once
106
+ `await client.load_controls()` has read them from `GET /v1/info`.
107
+
108
+ The controls marked "needs session controls" need a Satham server with session controls (its
109
+ `GET /v1/info` lists `controls`, as the server does since 2026-11-16); an older server refuses them
110
+ when the call starts. `greeting` and `agent` belong to the start of a call. Setting
111
+ `input_audio_noise_reduction`'s `mode` alone resets `strength_db` to that mode's preset, so send both
112
+ to keep a custom strength; `None` leaves noise reduction at the server's default (on), and `"none"`
113
+ turns it off. `agent` is
114
+ an optional preset on the server (such as a demo's) and is not needed.
115
+
116
+ <!-- controls -->
117
+ | Option | Range | Default | OpenAI equivalent | Notes |
118
+ | --- | --- | --- | --- | --- |
119
+ | `instructions` | text, up to 16000 characters | none | - | the agent's role; from the LiveKit agent or Pipecat context in the adapters |
120
+ | `greeting` | text, up to 1000 characters | none | - | said first; without one the caller speaks first |
121
+ | `tools` | up to 128 functions | none | - | preview: needs a server with tool support |
122
+ | `tool_choice` | see notes | "auto" | `tool_choice` | "auto", "none", "required" or one function |
123
+ | `agent` | text, up to 64 characters | none | - | optional: a preset agent on the server, such as a demo's |
124
+ | `model` | text, up to 64 characters | "satham-1" | `model` | "satham-1" only today; needs session controls |
125
+ | `modalities` | list | ["audio", "text"] | `modalities` | ["audio", "text"], ["audio"], or ["text"]: words only, for your own TTS; needs session controls |
126
+ | `language` | `auto`, `hi`, `ta`, `te`, `kn`, `bn`, `pa`, `en` | "auto" | - | |
127
+ | `language_switch` | `auto`, `off`, or `None` | "auto" | - | |
128
+ | `voice_on_language_switch` | `keep`, `native`, or `None` | "keep" | - | |
129
+ | `turn_detection.enabled` | `True` / `False` | true | `turn_detection=None` | false (or turn_detection=None): the client ends each turn; needs session controls |
130
+ | `turn_detection.type` | `server_vad`, `semantic_vad` | "server_vad" | `turn_detection.type` | needs session controls |
131
+ | `turn_detection.threshold` | 0.1 to 0.95 | 0.5 | `turn_detection.threshold` | the speech detector's threshold; needs session controls |
132
+ | `turn_detection.eagerness` | `auto`, `low`, `medium`, `high` | "auto" | `turn_detection.eagerness` | semantic_vad's end-of-turn wait; needs session controls |
133
+ | `turn_detection.prefix_padding_ms` | 0 to 1000 | 300 | `turn_detection.prefix_padding_ms` | needs session controls |
134
+ | `turn_detection.min_speech_ms` | 50 to 1000 | 100 | - | needs session controls |
135
+ | `turn_detection.silence_duration_ms` | 150 to 2000 | 350 | `turn_detection.silence_duration_ms` | server_vad's end-of-turn wait; needs session controls |
136
+ | `turn_detection.create_response` | `True` / `False` | true | `turn_detection.create_response` | answer each turn at once; needs session controls |
137
+ | `turn_detection.interrupt_response` | `True` / `False` | true | `turn_detection.interrupt_response` | barge-in on or off; needs session controls |
138
+ | `turn_detection.barge_in.min_speech_ms` | 0 to 2000 | 400 | - | needs session controls |
139
+ | `turn_detection.barge_in.min_probability` | 0 to 1 | 0.8 | - | needs session controls |
140
+ | `turn_detection.barge_in.min_dbfs` | -90 to 0, or `None` | -40 | - | needs session controls |
141
+ | `turn_detection.continue_within_ms` | 0 to 5000, or `None` | 2000 | - | the caller carrying on in the same turn; null: off; needs session controls |
142
+ | `turn_detection.continue_max_heard_ms` | 0 to 5000 | 1000 | - | needs session controls |
143
+ | `input_audio_noise_reduction.enabled` | `True` / `False` | true | `input_audio_noise_reduction={"type": "none"}` | false, "none" or {"type": "none"}: off; needs session controls |
144
+ | `input_audio_noise_reduction.mode` | `near_field`, `far_field` | "near_field" | `input_audio_noise_reduction.type` | resets strength_db to the mode's preset (12 or 30 dB) unless both are sent; needs session controls |
145
+ | `input_audio_noise_reduction.strength_db` | 0 to 100 | 12 | - | needs session controls |
146
+ | `input_audio_noise_reduction.apply_to_transcription` | `True` / `False` | false | - | needs session controls |
147
+ | `input_audio_transcription.enabled` | `True` / `False` | true | `input_audio_transcription=None` | transcript events to the client; needs session controls |
148
+ | `input_audio_transcription.code_mixed` | `True` / `False` | true | - | English words in Latin script, and digits; needs session controls |
149
+ | `voice` | text, up to 64 characters | the language's | `voice` | |
150
+ | `breaths` | `True` / `False`, or `None` | off | - | |
151
+ | `natural_pauses` | `True` / `False`, or `None` | off | - | |
152
+ | `continuation` | `True` / `False`, or `None` | true | - | each phrase carries on from the one before; needs session controls |
153
+ | `speed` | 1 to 1 | 1.0 | `speed` | 1.0 only today; needs session controls |
154
+ | `phrasing.first_phrase_max_chars` | 1 to 120 | 120 | - | at least min_phrase_chars; needs session controls |
155
+ | `phrasing.min_phrase_chars` | 1 to 120 | 20 | - | needs session controls |
156
+ | `normalise_numbers` | `True` / `False` | true | - | numbers and amounts said as words; needs session controls |
157
+ | `pronunciations` | word to respelling | none | - | {word: respelling}, up to 200; needs session controls |
158
+ | `temperature` | 0.6 to 1.2 | 0.7 | `temperature` | needs session controls |
159
+ | `top_p` | 0.05 to 1 | 0.8 | - | needs session controls |
160
+ | `max_response_output_tokens` | 1 to 4096 | 320 | `max_response_output_tokens` | or "inf"; never above the server's; needs session controls |
161
+ | `tone` | `auto`, `conversational`, `happy`, `sad`, `excited`, `professional` | "auto" | - | "auto": the model picks; needs session controls |
162
+ | `repeat_guard` | `True` / `False` | true | - | re-asks a reply that repeats a recent one; needs session controls |
163
+ | `drift_guard` | `True` / `False` | true | - | keeps replies in the call's language; needs session controls |
164
+ <!-- /controls -->
165
+
166
+ ## Events
167
+
168
+ Iterate the session, or `await call.recv()`. Every event keeps its message in `.raw`.
169
+
170
+ | Event | Fields |
171
+ | --- | --- |
172
+ | `SpeechStarted` / `SpeechStopped` | `turn_id`, `audio_ms`, `continues` |
173
+ | `TranscriptPartial` / `TranscriptFinal` | `turn_id`, `text`, `language`, `code_mixed` |
174
+ | `ResponseStarted` | `response_id`, `turn_id` (`"greeting"` for the opening line) |
175
+ | `ResponseTextDelta` | `response_id`, `text` |
176
+ | `ResponseAudio` | `response_id`, `data` (PCM), `format`, `duration_ms` |
177
+ | `ResponseDone` | `response_id`, `text`, `audio_ms`, `metrics` |
178
+ | `ResponseInterrupted` | `response_id`, `reason` (`barge_in`, `client_cancel`, `session_closed`) |
179
+ | `ToolCall` | `call_id`, `name`, `arguments` (JSON text), `args` (parsed) |
180
+ | `SessionUpdated` | `language`, `reason` (`caller`, `reply`, `client`) |
181
+ | `Error` | `code`, `message`, `fatal` |
182
+ | `SessionEnded` | `reason` |
183
+
184
+ On `SpeechStarted` or `ResponseInterrupted`, drop any agent audio not yet played.
185
+
186
+ ## Tools (preview)
187
+
188
+ Preview: tools need a Satham server with tool support (`(await client.info()).get("tools")` is true).
189
+
190
+ ```python
191
+ @satham.function_tool
192
+ def end_call(reason: str = "the conversation is over") -> None:
193
+ """End the call when the conversation is over. Say a short goodbye in the same turn."""
194
+
195
+
196
+ async with satham.connect(url, api_key, instructions=ROLE, tools=[end_call]) as call:
197
+ async for event in call:
198
+ if isinstance(event, satham.ToolCall) and event.name == "end_call":
199
+ await call.send_tool_result(event, "ended", respond=False) # no reply wanted
200
+ ```
201
+
202
+ `function_tool` builds the JSON schema from the signature and the docstring; `FunctionTool(name,
203
+ description, parameters)` or a plain OpenAI-style function definition work too.
204
+ `send_tool_result(call, output)` takes a string or any JSON value; with `respond=True` (the default)
205
+ the agent replies once every call of that reply has its result.
206
+
207
+ ## Testing your app
208
+
209
+ `satham.testing.MockServer` is a local stand-in server with a scripted conversation: loud audio is
210
+ speech, quiet ends the turn, and `MockTurn(transcript=..., reply=..., language=..., tool_call=...)`
211
+ entries answer each turn. `MockServer(controls=False)` behaves as a server without session controls.
212
+
213
+ ```python
214
+ from satham.testing import MockServer, MockTurn
215
+
216
+ async with MockServer(turns=[MockTurn(transcript="hi", reply="Hello!")]) as server:
217
+ call = await satham.connect(server.url, instructions="You are a test agent.")
218
+ await call.send_audio(MockServer.tone(300) + MockServer.silence(300))
219
+ ```
satham-0.1.0/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # satham
2
+
3
+ An async Python client for Satham's realtime speech-to-speech API. Your agent brings its own
4
+ instructions, greeting and tools; you connect to your Satham endpoint with your API key, stream the
5
+ caller's audio in and the agent's audio out, follow transcripts, interruptions and language changes,
6
+ answer tool calls, and change any of the call's controls while it runs.
7
+
8
+ Python 3.11+. One dependency: `websockets`.
9
+
10
+ ```sh
11
+ pip install satham
12
+ ```
13
+
14
+ Framework adapters: [`livekit-plugins-satham`](https://pypi.org/project/livekit-plugins-satham/) for
15
+ LiveKit Agents and [`pipecat-satham`](https://pypi.org/project/pipecat-satham/) for Pipecat.
16
+
17
+ ## A call
18
+
19
+ You pass your Satham endpoint and API key (or set `SATHAM_URL` and `SATHAM_API_KEY`); there is no
20
+ default server.
21
+
22
+ ```python
23
+ import asyncio
24
+ import os
25
+
26
+ import satham
27
+
28
+ ROLE = "You are Asha, who books site visits for Example Homes. Keep every reply short."
29
+
30
+
31
+ async def main() -> None:
32
+ async with satham.connect(
33
+ os.environ["SATHAM_URL"], # your Satham endpoint, wss://... or https://...
34
+ os.environ["SATHAM_API_KEY"],
35
+ instructions=ROLE, # the agent's role: your prompt
36
+ greeting="Hello, this is Asha from Example Homes. Is this a good time?",
37
+ language="en", # or "auto"; the call can follow the caller into another language
38
+ language_switch="auto",
39
+ sample_rate=16_000, # the caller audio you send: 16-bit mono PCM
40
+ ) as call:
41
+ asyncio.create_task(stream_microphone(call)) # await call.send_audio(pcm) per packet
42
+ async for event in call:
43
+ match event:
44
+ case satham.ResponseAudio():
45
+ speaker.write(event.data) # PCM in call.output_audio's format
46
+ case satham.SpeechStarted() | satham.ResponseInterrupted():
47
+ speaker.clear() # the caller is talking: stop at once
48
+ case satham.TranscriptFinal():
49
+ print("caller:", event.text, event.language)
50
+ case satham.ResponseDone():
51
+ print("agent:", event.text)
52
+ case satham.SessionUpdated():
53
+ print("now in", event.language, "because of the", event.reason)
54
+
55
+
56
+ asyncio.run(main())
57
+ ```
58
+
59
+ Without a `greeting` the caller speaks first. `connect()` raises `AuthenticationError`,
60
+ `ServerBusyError`, `InvalidRequestError` (a refused setting) or `SathamError` (connection failures
61
+ and timeouts; `.code` says which). A bad value fails in the client with `ValueError` before anything
62
+ is sent.
63
+
64
+ During the call, `await call.update(...)` changes any control (the same names as `connect`; only what
65
+ you pass is sent, and `instructions` can change too), `call.commit()` ends the caller's turn now
66
+ (push-to-talk), `call.cancel()` stops the reply, and `call.close()` ends the call. `call.language`
67
+ follows every language change.
68
+
69
+ Replies on demand: `await call.create_response(instructions=None)` asks for a reply now (to open the
70
+ call, or after a quiet spell; `instructions` guide that reply alone), and `await call.say(text)` has
71
+ the agent say fixed words in its voice. While a reply is under way, or the caller is speaking, the
72
+ server answers with a non-fatal `response_in_progress` error.
73
+
74
+ ## Controls
75
+
76
+ Every keyword of `connect()` and `update()` besides the URL, key and audio format is a control
77
+ (`satham.SessionControls`, a `TypedDict`). OpenAI's names are used where LiveKit's OpenAI realtime
78
+ plugin has one; groups (`turn_detection`, `input_audio_noise_reduction`, `input_audio_transcription`,
79
+ `phrasing`) are dicts of the keys shown. A control you leave out is not sent, so the server's default
80
+ holds. Values are checked against the ranges below, or against your server's once
81
+ `await client.load_controls()` has read them from `GET /v1/info`.
82
+
83
+ The controls marked "needs session controls" need a Satham server with session controls (its
84
+ `GET /v1/info` lists `controls`, as the server does since 2026-11-16); an older server refuses them
85
+ when the call starts. `greeting` and `agent` belong to the start of a call. Setting
86
+ `input_audio_noise_reduction`'s `mode` alone resets `strength_db` to that mode's preset, so send both
87
+ to keep a custom strength; `None` leaves noise reduction at the server's default (on), and `"none"`
88
+ turns it off. `agent` is
89
+ an optional preset on the server (such as a demo's) and is not needed.
90
+
91
+ <!-- controls -->
92
+ | Option | Range | Default | OpenAI equivalent | Notes |
93
+ | --- | --- | --- | --- | --- |
94
+ | `instructions` | text, up to 16000 characters | none | - | the agent's role; from the LiveKit agent or Pipecat context in the adapters |
95
+ | `greeting` | text, up to 1000 characters | none | - | said first; without one the caller speaks first |
96
+ | `tools` | up to 128 functions | none | - | preview: needs a server with tool support |
97
+ | `tool_choice` | see notes | "auto" | `tool_choice` | "auto", "none", "required" or one function |
98
+ | `agent` | text, up to 64 characters | none | - | optional: a preset agent on the server, such as a demo's |
99
+ | `model` | text, up to 64 characters | "satham-1" | `model` | "satham-1" only today; needs session controls |
100
+ | `modalities` | list | ["audio", "text"] | `modalities` | ["audio", "text"], ["audio"], or ["text"]: words only, for your own TTS; needs session controls |
101
+ | `language` | `auto`, `hi`, `ta`, `te`, `kn`, `bn`, `pa`, `en` | "auto" | - | |
102
+ | `language_switch` | `auto`, `off`, or `None` | "auto" | - | |
103
+ | `voice_on_language_switch` | `keep`, `native`, or `None` | "keep" | - | |
104
+ | `turn_detection.enabled` | `True` / `False` | true | `turn_detection=None` | false (or turn_detection=None): the client ends each turn; needs session controls |
105
+ | `turn_detection.type` | `server_vad`, `semantic_vad` | "server_vad" | `turn_detection.type` | needs session controls |
106
+ | `turn_detection.threshold` | 0.1 to 0.95 | 0.5 | `turn_detection.threshold` | the speech detector's threshold; needs session controls |
107
+ | `turn_detection.eagerness` | `auto`, `low`, `medium`, `high` | "auto" | `turn_detection.eagerness` | semantic_vad's end-of-turn wait; needs session controls |
108
+ | `turn_detection.prefix_padding_ms` | 0 to 1000 | 300 | `turn_detection.prefix_padding_ms` | needs session controls |
109
+ | `turn_detection.min_speech_ms` | 50 to 1000 | 100 | - | needs session controls |
110
+ | `turn_detection.silence_duration_ms` | 150 to 2000 | 350 | `turn_detection.silence_duration_ms` | server_vad's end-of-turn wait; needs session controls |
111
+ | `turn_detection.create_response` | `True` / `False` | true | `turn_detection.create_response` | answer each turn at once; needs session controls |
112
+ | `turn_detection.interrupt_response` | `True` / `False` | true | `turn_detection.interrupt_response` | barge-in on or off; needs session controls |
113
+ | `turn_detection.barge_in.min_speech_ms` | 0 to 2000 | 400 | - | needs session controls |
114
+ | `turn_detection.barge_in.min_probability` | 0 to 1 | 0.8 | - | needs session controls |
115
+ | `turn_detection.barge_in.min_dbfs` | -90 to 0, or `None` | -40 | - | needs session controls |
116
+ | `turn_detection.continue_within_ms` | 0 to 5000, or `None` | 2000 | - | the caller carrying on in the same turn; null: off; needs session controls |
117
+ | `turn_detection.continue_max_heard_ms` | 0 to 5000 | 1000 | - | needs session controls |
118
+ | `input_audio_noise_reduction.enabled` | `True` / `False` | true | `input_audio_noise_reduction={"type": "none"}` | false, "none" or {"type": "none"}: off; needs session controls |
119
+ | `input_audio_noise_reduction.mode` | `near_field`, `far_field` | "near_field" | `input_audio_noise_reduction.type` | resets strength_db to the mode's preset (12 or 30 dB) unless both are sent; needs session controls |
120
+ | `input_audio_noise_reduction.strength_db` | 0 to 100 | 12 | - | needs session controls |
121
+ | `input_audio_noise_reduction.apply_to_transcription` | `True` / `False` | false | - | needs session controls |
122
+ | `input_audio_transcription.enabled` | `True` / `False` | true | `input_audio_transcription=None` | transcript events to the client; needs session controls |
123
+ | `input_audio_transcription.code_mixed` | `True` / `False` | true | - | English words in Latin script, and digits; needs session controls |
124
+ | `voice` | text, up to 64 characters | the language's | `voice` | |
125
+ | `breaths` | `True` / `False`, or `None` | off | - | |
126
+ | `natural_pauses` | `True` / `False`, or `None` | off | - | |
127
+ | `continuation` | `True` / `False`, or `None` | true | - | each phrase carries on from the one before; needs session controls |
128
+ | `speed` | 1 to 1 | 1.0 | `speed` | 1.0 only today; needs session controls |
129
+ | `phrasing.first_phrase_max_chars` | 1 to 120 | 120 | - | at least min_phrase_chars; needs session controls |
130
+ | `phrasing.min_phrase_chars` | 1 to 120 | 20 | - | needs session controls |
131
+ | `normalise_numbers` | `True` / `False` | true | - | numbers and amounts said as words; needs session controls |
132
+ | `pronunciations` | word to respelling | none | - | {word: respelling}, up to 200; needs session controls |
133
+ | `temperature` | 0.6 to 1.2 | 0.7 | `temperature` | needs session controls |
134
+ | `top_p` | 0.05 to 1 | 0.8 | - | needs session controls |
135
+ | `max_response_output_tokens` | 1 to 4096 | 320 | `max_response_output_tokens` | or "inf"; never above the server's; needs session controls |
136
+ | `tone` | `auto`, `conversational`, `happy`, `sad`, `excited`, `professional` | "auto" | - | "auto": the model picks; needs session controls |
137
+ | `repeat_guard` | `True` / `False` | true | - | re-asks a reply that repeats a recent one; needs session controls |
138
+ | `drift_guard` | `True` / `False` | true | - | keeps replies in the call's language; needs session controls |
139
+ <!-- /controls -->
140
+
141
+ ## Events
142
+
143
+ Iterate the session, or `await call.recv()`. Every event keeps its message in `.raw`.
144
+
145
+ | Event | Fields |
146
+ | --- | --- |
147
+ | `SpeechStarted` / `SpeechStopped` | `turn_id`, `audio_ms`, `continues` |
148
+ | `TranscriptPartial` / `TranscriptFinal` | `turn_id`, `text`, `language`, `code_mixed` |
149
+ | `ResponseStarted` | `response_id`, `turn_id` (`"greeting"` for the opening line) |
150
+ | `ResponseTextDelta` | `response_id`, `text` |
151
+ | `ResponseAudio` | `response_id`, `data` (PCM), `format`, `duration_ms` |
152
+ | `ResponseDone` | `response_id`, `text`, `audio_ms`, `metrics` |
153
+ | `ResponseInterrupted` | `response_id`, `reason` (`barge_in`, `client_cancel`, `session_closed`) |
154
+ | `ToolCall` | `call_id`, `name`, `arguments` (JSON text), `args` (parsed) |
155
+ | `SessionUpdated` | `language`, `reason` (`caller`, `reply`, `client`) |
156
+ | `Error` | `code`, `message`, `fatal` |
157
+ | `SessionEnded` | `reason` |
158
+
159
+ On `SpeechStarted` or `ResponseInterrupted`, drop any agent audio not yet played.
160
+
161
+ ## Tools (preview)
162
+
163
+ Preview: tools need a Satham server with tool support (`(await client.info()).get("tools")` is true).
164
+
165
+ ```python
166
+ @satham.function_tool
167
+ def end_call(reason: str = "the conversation is over") -> None:
168
+ """End the call when the conversation is over. Say a short goodbye in the same turn."""
169
+
170
+
171
+ async with satham.connect(url, api_key, instructions=ROLE, tools=[end_call]) as call:
172
+ async for event in call:
173
+ if isinstance(event, satham.ToolCall) and event.name == "end_call":
174
+ await call.send_tool_result(event, "ended", respond=False) # no reply wanted
175
+ ```
176
+
177
+ `function_tool` builds the JSON schema from the signature and the docstring; `FunctionTool(name,
178
+ description, parameters)` or a plain OpenAI-style function definition work too.
179
+ `send_tool_result(call, output)` takes a string or any JSON value; with `respond=True` (the default)
180
+ the agent replies once every call of that reply has its result.
181
+
182
+ ## Testing your app
183
+
184
+ `satham.testing.MockServer` is a local stand-in server with a scripted conversation: loud audio is
185
+ speech, quiet ends the turn, and `MockTurn(transcript=..., reply=..., language=..., tool_call=...)`
186
+ entries answer each turn. `MockServer(controls=False)` behaves as a server without session controls.
187
+
188
+ ```python
189
+ from satham.testing import MockServer, MockTurn
190
+
191
+ async with MockServer(turns=[MockTurn(transcript="hi", reply="Hello!")]) as server:
192
+ call = await satham.connect(server.url, instructions="You are a test agent.")
193
+ await call.send_audio(MockServer.tone(300) + MockServer.silence(300))
194
+ ```
@@ -0,0 +1,38 @@
1
+ [project]
2
+ name = "satham"
3
+ version = "0.1.0"
4
+ description = "Async Python client for Satham's realtime speech-to-speech API"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "Apache-2.0"
8
+ license-files = ["LICENSE"]
9
+ authors = [{ name = "Satham" }]
10
+ keywords = ["satham", "speech-to-speech", "voice-agent", "realtime", "websocket", "speech", "indian-languages", "hindi", "tamil", "telugu"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Operating System :: OS Independent",
15
+ "Framework :: AsyncIO",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Topic :: Multimedia :: Sound/Audio :: Speech",
21
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
22
+ "Topic :: Software Development :: Libraries :: Python Modules",
23
+ "Typing :: Typed",
24
+ ]
25
+ dependencies = ["websockets>=13.1,<18"]
26
+
27
+ [project.urls]
28
+ Homepage = "https://satham.ai"
29
+
30
+ [build-system]
31
+ requires = ["hatchling==1.27.0"]
32
+ build-backend = "hatchling.build"
33
+
34
+ [tool.hatch.build.targets.wheel]
35
+ packages = ["src/satham"]
36
+
37
+ [tool.hatch.build.targets.sdist]
38
+ include = ["src/satham", "README.md", "LICENSE"]