livekit-plugins-munsit 0.3.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,156 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .nox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ *.py,cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+ cover/
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Django stuff:
57
+ *.log
58
+ local_settings.py
59
+ db.sqlite3
60
+ db.sqlite3-journal
61
+
62
+ # Flask stuff:
63
+ instance/
64
+ .webassets-cache
65
+
66
+ # Scrapy stuff:
67
+ .scrapy
68
+
69
+ # Sphinx documentation
70
+ docs/_build/
71
+
72
+ # PyBuilder
73
+ .pybuilder/
74
+ target/
75
+
76
+ # Jupyter Notebook
77
+ .ipynb_checkpoints
78
+
79
+ # IPython
80
+ profile_default/
81
+ ipython_config.py
82
+
83
+ # pyenv
84
+ .python-version
85
+
86
+ # pipenv
87
+ Pipfile.lock
88
+
89
+ # poetry
90
+ poetry.lock
91
+
92
+ # pdm
93
+ .pdm.toml
94
+
95
+ # PEP 582
96
+ __pypackages__/
97
+
98
+ # Celery stuff
99
+ celerybeat-schedule
100
+ celerybeat.pid
101
+
102
+ # SageMath parsed files
103
+ *.sage.py
104
+
105
+ # Environments
106
+ .env
107
+ .venv
108
+ env/
109
+ venv/
110
+ ENV/
111
+ env.bak/
112
+ venv.bak/
113
+
114
+ # Spyder project settings
115
+ .spyderproject
116
+ .spyproject
117
+
118
+ # Rope project settings
119
+ .ropeproject
120
+
121
+ # mkdocs documentation
122
+ /site
123
+
124
+ # mypy
125
+ .mypy_cache/
126
+ .dmypy.json
127
+ dmypy.json
128
+
129
+ # Pyre type checker
130
+ .pyre/
131
+
132
+ # pytype static type analyzer
133
+ .pytype/
134
+
135
+ # Cython debug symbols
136
+ cython_debug/
137
+
138
+ # IDEs
139
+ .vscode/
140
+ .idea/
141
+ *.swp
142
+ *.swo
143
+ *~
144
+
145
+ # OS
146
+ .DS_Store
147
+ Thumbs.db
148
+
149
+ # Project specific
150
+ *.pcm
151
+ *.wav
152
+ *.mp3
153
+ test_output/
154
+
155
+ # Test fixtures we DO want tracked (must come after *.wav above).
156
+ !tests/sample_arabic.wav
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Support. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Khalid Ghiboub
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: livekit-plugins-munsit
3
+ Version: 0.3.0
4
+ Summary: LiveKit Agents plugin for Munsit speech-to-text (Arabic + Arabic/English code-switching). Successor to livekit-plugins-faseeh.
5
+ Project-URL: Homepage, https://github.com/CNTXTFZCO0/livekit-plugins-munsit
6
+ Project-URL: Documentation, https://github.com/CNTXTFZCO0/livekit-plugins-munsit#readme
7
+ Project-URL: Repository, https://github.com/CNTXTFZCO0/livekit-plugins-munsit
8
+ Project-URL: Bug Tracker, https://github.com/CNTXTFZCO0/livekit-plugins-munsit/issues
9
+ Project-URL: Munsit, https://munsit.com
10
+ Author-email: Mohan Raj Palanisamy <mohanraj.palanisamy@cntxt.tech>
11
+ Maintainer-email: Mohan Raj Palanisamy <mohanraj.palanisamy@cntxt.tech>
12
+ License-Expression: Apache-2.0
13
+ License-File: LICENSE
14
+ Keywords: ai,arabic,audio,faseeh,livekit,munsit,realtime,speech-to-text,stt,voice
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Multimedia :: Sound/Audio
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Requires-Python: >=3.10.0
26
+ Requires-Dist: aiohttp>=3.8.0
27
+ Requires-Dist: livekit-agents[codecs]>=1.4.4
28
+ Requires-Dist: numpy>=1.26
29
+ Description-Content-Type: text/markdown
30
+
31
+ # LiveKit Plugins Munsit
32
+
33
+ STT plugin for [Munsit](https://munsit.com), the merged Faseeh + Munsit ASR product. Optimized for Arabic with optional Arabic/English code-switching (`munsit-en-ar` model).
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install livekit-plugins-munsit
39
+ ```
40
+
41
+ (While developing inside this monorepo, use `uv sync --all-extras --dev`.)
42
+
43
+ ## Quickstart
44
+
45
+ ```python
46
+ from livekit.agents import AgentSession
47
+ from livekit.plugins import munsit, silero
48
+
49
+ session = AgentSession(
50
+ stt=munsit.STT(), # batch mode is the default
51
+ vad=silero.VAD.load(),
52
+ # ... llm, tts ...
53
+ )
54
+ ```
55
+
56
+ `MUNSIT_API_KEY` is read from the environment by default. Munsit's batch HTTP endpoint is more accurate and returns word-level timestamps; we use it by default. The `AgentSession`'s VAD signals end-of-speech via `flush()`, which causes the plugin to POST the buffered utterance and emit a single `FINAL_TRANSCRIPT` with per-word timings.
57
+
58
+ ## Modes
59
+
60
+ | Mode | When to use | Endpoint | Latency | Word timestamps | Interim events |
61
+ |---|---|---|---|---|---|
62
+ | `"batch"` (default) | Production with `AgentSession` + VAD; transcribing recorded audio. | `POST /api/v1/audio/transcribe` | VAD detection + upload + server processing (~1–2 s for short utterances) | yes — populated on `SpeechData.words` | no |
63
+ | `"streaming"` | You need live captions / on-the-fly UI updates while the user is still speaking. | WebSocket `/api/v1/websocket/speech-to-text` | ~700 ms idle threshold by default | no | yes (`INTERIM_TRANSCRIPT` flow as cumulatives arrive) |
64
+
65
+ ```python
66
+ munsit.STT() # batch (default)
67
+ munsit.STT(mode="streaming") # opt-in for low-latency interims
68
+ ```
69
+
70
+ `STT.recognize(audio_buffer)` always uses the batch HTTP endpoint regardless of `mode`.
71
+
72
+ ## Parameters
73
+
74
+ | Param | Default | Notes |
75
+ |---|---|---|
76
+ | `mode` | `"batch"` | `"batch"` (HTTP) or `"streaming"` (WS). |
77
+ | `model` | `"munsit"` | `"munsit"` (Arabic) or `"munsit-en-ar"` (code-switching). |
78
+ | `api_key` | `MUNSIT_API_KEY` env | Required. |
79
+ | `base_url` | Munsit prod WSS | Override the streaming WebSocket URL. |
80
+ | `batch_base_url` | Munsit prod HTTPS | Override the batch HTTP URL. |
81
+ | `auth_method` | `"header"` | `"header"` / `"bearer"` / `"query"` — Munsit accepts all three on both endpoints. |
82
+ | `sample_rate` | `16000` | Used for the synthesized WAV header. |
83
+ | `num_channels` | `1` | |
84
+ | `interim_results` | `True` | Emit `INTERIM_TRANSCRIPT` events. Only meaningful in streaming mode. |
85
+ | `endpointing` | `"server_diff"` | Streaming-mode only: `"server_diff"` (idle timer) or `"client_vad"` (energy-based). |
86
+ | `finalize_after_silence_ms` | `700` | Streaming-mode `server_diff` idle threshold. |
87
+ | `energy_filter` | `False` | Streaming-mode `client_vad` only. |
88
+ | `vad_silence_ms` | `1500` | Streaming-mode `client_vad` silence-end duration. |
89
+ | `language` | `None` | Label attached to `SpeechData.language`. Defaults to `"ar"`. |
90
+ | `http_session` | `None` | Custom `aiohttp.ClientSession`. |
91
+ | `extra_query_params` | `None` | Forward-compat for new Munsit query params (streaming WS only). |
92
+
93
+ ## Streaming mode endpointing
94
+
95
+ When using `mode="streaming"`, the plugin offers two end-of-utterance strategies:
96
+
97
+ - **`server_diff`** (default) — keep one long-lived WS open, emit `INTERIM_TRANSCRIPT` on each transcript update, emit `FINAL_TRANSCRIPT` + `END_OF_SPEECH` after `finalize_after_silence_ms` of server silence. Best when `AgentSession` already has its own VAD / turn detector.
98
+ - **`client_vad`** — open WS on local energy onset, close on silence end. Each utterance gets a fresh WS connection. Slightly higher per-utterance latency but harder utterance boundaries.
99
+
100
+ ## Examples
101
+
102
+ See [`examples/README.md`](examples/README.md). Three demos cover file-based, mic-based, and full-agent scenarios. The file demo prints per-word timings when batch mode is active.
@@ -0,0 +1,72 @@
1
+ # LiveKit Plugins Munsit
2
+
3
+ STT plugin for [Munsit](https://munsit.com), the merged Faseeh + Munsit ASR product. Optimized for Arabic with optional Arabic/English code-switching (`munsit-en-ar` model).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install livekit-plugins-munsit
9
+ ```
10
+
11
+ (While developing inside this monorepo, use `uv sync --all-extras --dev`.)
12
+
13
+ ## Quickstart
14
+
15
+ ```python
16
+ from livekit.agents import AgentSession
17
+ from livekit.plugins import munsit, silero
18
+
19
+ session = AgentSession(
20
+ stt=munsit.STT(), # batch mode is the default
21
+ vad=silero.VAD.load(),
22
+ # ... llm, tts ...
23
+ )
24
+ ```
25
+
26
+ `MUNSIT_API_KEY` is read from the environment by default. Munsit's batch HTTP endpoint is more accurate and returns word-level timestamps; we use it by default. The `AgentSession`'s VAD signals end-of-speech via `flush()`, which causes the plugin to POST the buffered utterance and emit a single `FINAL_TRANSCRIPT` with per-word timings.
27
+
28
+ ## Modes
29
+
30
+ | Mode | When to use | Endpoint | Latency | Word timestamps | Interim events |
31
+ |---|---|---|---|---|---|
32
+ | `"batch"` (default) | Production with `AgentSession` + VAD; transcribing recorded audio. | `POST /api/v1/audio/transcribe` | VAD detection + upload + server processing (~1–2 s for short utterances) | yes — populated on `SpeechData.words` | no |
33
+ | `"streaming"` | You need live captions / on-the-fly UI updates while the user is still speaking. | WebSocket `/api/v1/websocket/speech-to-text` | ~700 ms idle threshold by default | no | yes (`INTERIM_TRANSCRIPT` flow as cumulatives arrive) |
34
+
35
+ ```python
36
+ munsit.STT() # batch (default)
37
+ munsit.STT(mode="streaming") # opt-in for low-latency interims
38
+ ```
39
+
40
+ `STT.recognize(audio_buffer)` always uses the batch HTTP endpoint regardless of `mode`.
41
+
42
+ ## Parameters
43
+
44
+ | Param | Default | Notes |
45
+ |---|---|---|
46
+ | `mode` | `"batch"` | `"batch"` (HTTP) or `"streaming"` (WS). |
47
+ | `model` | `"munsit"` | `"munsit"` (Arabic) or `"munsit-en-ar"` (code-switching). |
48
+ | `api_key` | `MUNSIT_API_KEY` env | Required. |
49
+ | `base_url` | Munsit prod WSS | Override the streaming WebSocket URL. |
50
+ | `batch_base_url` | Munsit prod HTTPS | Override the batch HTTP URL. |
51
+ | `auth_method` | `"header"` | `"header"` / `"bearer"` / `"query"` — Munsit accepts all three on both endpoints. |
52
+ | `sample_rate` | `16000` | Used for the synthesized WAV header. |
53
+ | `num_channels` | `1` | |
54
+ | `interim_results` | `True` | Emit `INTERIM_TRANSCRIPT` events. Only meaningful in streaming mode. |
55
+ | `endpointing` | `"server_diff"` | Streaming-mode only: `"server_diff"` (idle timer) or `"client_vad"` (energy-based). |
56
+ | `finalize_after_silence_ms` | `700` | Streaming-mode `server_diff` idle threshold. |
57
+ | `energy_filter` | `False` | Streaming-mode `client_vad` only. |
58
+ | `vad_silence_ms` | `1500` | Streaming-mode `client_vad` silence-end duration. |
59
+ | `language` | `None` | Label attached to `SpeechData.language`. Defaults to `"ar"`. |
60
+ | `http_session` | `None` | Custom `aiohttp.ClientSession`. |
61
+ | `extra_query_params` | `None` | Forward-compat for new Munsit query params (streaming WS only). |
62
+
63
+ ## Streaming mode endpointing
64
+
65
+ When using `mode="streaming"`, the plugin offers two end-of-utterance strategies:
66
+
67
+ - **`server_diff`** (default) — keep one long-lived WS open, emit `INTERIM_TRANSCRIPT` on each transcript update, emit `FINAL_TRANSCRIPT` + `END_OF_SPEECH` after `finalize_after_silence_ms` of server silence. Best when `AgentSession` already has its own VAD / turn detector.
68
+ - **`client_vad`** — open WS on local energy onset, close on silence end. Each utterance gets a fresh WS connection. Slightly higher per-utterance latency but harder utterance boundaries.
69
+
70
+ ## Examples
71
+
72
+ See [`examples/README.md`](examples/README.md). Three demos cover file-based, mic-based, and full-agent scenarios. The file demo prints per-word timings when batch mode is active.
@@ -0,0 +1,33 @@
1
+ """Munsit plugin for LiveKit Agents.
2
+
3
+ See https://docs.munsit.com for the upstream API documentation.
4
+ """
5
+
6
+ from ._utils import AudioEnergyFilter
7
+ from .models import MunsitModels
8
+ from .stt import STT, SpeechStream
9
+ from .version import __version__
10
+
11
+ __all__ = ["STT", "SpeechStream", "AudioEnergyFilter", "MunsitModels", "__version__"]
12
+
13
+
14
+ from livekit.agents import Plugin
15
+
16
+ from .log import logger
17
+
18
+
19
+ class MunsitPlugin(Plugin):
20
+ def __init__(self) -> None:
21
+ super().__init__(__name__, __version__, __package__, logger)
22
+
23
+
24
+ Plugin.register_plugin(MunsitPlugin())
25
+
26
+ # Cleanup docs of unexported modules
27
+ _module = dir()
28
+ NOT_IN_ALL = [m for m in _module if m not in __all__]
29
+
30
+ __pdoc__ = {}
31
+
32
+ for n in NOT_IN_ALL:
33
+ __pdoc__[n] = False
@@ -0,0 +1,129 @@
1
+ # Copyright 2026 LiveKit, Inc.
2
+ from __future__ import annotations
3
+
4
+ import struct
5
+ import time
6
+ from collections.abc import Callable
7
+ from enum import Enum
8
+ from typing import Generic, TypeVar
9
+
10
+ import numpy as np
11
+
12
+ from livekit import rtc
13
+
14
+
15
+ def build_wav_header(
16
+ *, sample_rate: int, num_channels: int = 1, bits_per_sample: int = 16
17
+ ) -> bytes:
18
+ """Build a 44-byte PCM WAV header.
19
+
20
+ The data chunk size is set to a sentinel max value (0xFFFFFFFF - 44) because we are streaming
21
+ and don't know the total size in advance. Munsit only validates the format fields.
22
+ """
23
+ if sample_rate <= 0:
24
+ raise ValueError("sample_rate must be positive")
25
+ if num_channels <= 0:
26
+ raise ValueError("num_channels must be positive")
27
+ if bits_per_sample not in (8, 16, 24, 32):
28
+ raise ValueError("bits_per_sample must be 8, 16, 24, or 32")
29
+
30
+ byte_rate = sample_rate * num_channels * bits_per_sample // 8
31
+ block_align = num_channels * bits_per_sample // 8
32
+ data_size = 0xFFFFFFFF - 44
33
+ riff_size = data_size + 36
34
+
35
+ return (
36
+ b"RIFF"
37
+ + struct.pack("<I", riff_size)
38
+ + b"WAVE"
39
+ + b"fmt "
40
+ + struct.pack("<I", 16) # fmt chunk size
41
+ + struct.pack("<H", 1) # PCM format
42
+ + struct.pack("<H", num_channels)
43
+ + struct.pack("<I", sample_rate)
44
+ + struct.pack("<I", byte_rate)
45
+ + struct.pack("<H", block_align)
46
+ + struct.pack("<H", bits_per_sample)
47
+ + b"data"
48
+ + struct.pack("<I", data_size)
49
+ )
50
+
51
+
52
+ def pcm_to_audiobuffer(data: bytes) -> list[int]:
53
+ """Encode raw PCM bytes as Munsit's `audioBuffer` JSON int array (0-255 per byte)."""
54
+ return list(data)
55
+
56
+
57
+ T = TypeVar("T")
58
+
59
+
60
+ class PeriodicCollector(Generic[T]):
61
+ """Accumulate values and call ``callback`` once per ``duration`` seconds.
62
+
63
+ Used by SpeechStream to batch audio-duration reports so RECOGNITION_USAGE
64
+ events don't fire on every push.
65
+ """
66
+
67
+ def __init__(self, callback: Callable[[T], None], *, duration: float) -> None:
68
+ self._duration = duration
69
+ self._callback = callback
70
+ self._last_flush_time = time.monotonic()
71
+ self._total: T | None = None
72
+
73
+ def push(self, value: T) -> None:
74
+ if self._total is None:
75
+ self._total = value
76
+ else:
77
+ self._total += value # type: ignore[operator]
78
+ if time.monotonic() - self._last_flush_time >= self._duration:
79
+ self.flush()
80
+
81
+ def flush(self) -> None:
82
+ if self._total is not None:
83
+ self._callback(self._total)
84
+ self._total = None
85
+ self._last_flush_time = time.monotonic()
86
+
87
+
88
+ _DEFAULT_RMS_THRESHOLD = 0.004**2
89
+
90
+
91
+ class AudioEnergyFilter:
92
+ """Simple RMS-based VAD copied from the Gladia plugin pattern."""
93
+
94
+ class State(Enum):
95
+ START = 0
96
+ SPEAKING = 1
97
+ SILENCE = 2
98
+ END = 3
99
+
100
+ def __init__(
101
+ self, *, min_silence: float = 1.5, rms_threshold: float = _DEFAULT_RMS_THRESHOLD
102
+ ) -> None:
103
+ self._cooldown_seconds = min_silence
104
+ self._cooldown = min_silence
105
+ self._state = self.State.SILENCE
106
+ self._rms_threshold = rms_threshold
107
+
108
+ def update(self, frame: rtc.AudioFrame) -> AudioEnergyFilter.State:
109
+ arr = np.frombuffer(frame.data, dtype=np.int16)
110
+ float_arr = arr.astype(np.float32) / 32768.0
111
+ rms = float(np.mean(np.square(float_arr)))
112
+
113
+ if rms > self._rms_threshold:
114
+ self._cooldown = self._cooldown_seconds
115
+ if self._state in (self.State.SILENCE, self.State.END):
116
+ self._state = self.State.START
117
+ else:
118
+ self._state = self.State.SPEAKING
119
+ else:
120
+ if self._cooldown <= 0:
121
+ if self._state in (self.State.SPEAKING, self.State.START):
122
+ self._state = self.State.END
123
+ elif self._state == self.State.END:
124
+ self._state = self.State.SILENCE
125
+ else:
126
+ self._cooldown -= frame.duration
127
+ self._state = self.State.SPEAKING
128
+
129
+ return self._state
@@ -0,0 +1,3 @@
1
+ import logging
2
+
3
+ logger = logging.getLogger("livekit.plugins.munsit")