poly-server 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.
- poly_server-0.1.0/.gitignore +211 -0
- poly_server-0.1.0/LICENSE +21 -0
- poly_server-0.1.0/PKG-INFO +139 -0
- poly_server-0.1.0/README.md +108 -0
- poly_server-0.1.0/pyproject.toml +50 -0
- poly_server-0.1.0/src/poly_server/__init__.py +8 -0
- poly_server-0.1.0/src/poly_server/__main__.py +3 -0
- poly_server-0.1.0/src/poly_server/app.py +210 -0
- poly_server-0.1.0/src/poly_server/asr.py +76 -0
- poly_server-0.1.0/src/poly_server/cli.py +94 -0
- poly_server-0.1.0/src/poly_server/config.py +71 -0
- poly_server-0.1.0/src/poly_server/events.py +39 -0
- poly_server-0.1.0/src/poly_server/listening.py +104 -0
- poly_server-0.1.0/src/poly_server/mic.py +78 -0
- poly_server-0.1.0/src/poly_server/translate.py +151 -0
- poly_server-0.1.0/src/poly_server/vad.py +110 -0
- poly_server-0.1.0/tests/conftest.py +53 -0
- poly_server-0.1.0/tests/samples/en-US.mp3 +0 -0
- poly_server-0.1.0/tests/samples/fr-FR.mp3 +0 -0
- poly_server-0.1.0/tests/samples/ja-JP.mp3 +0 -0
- poly_server-0.1.0/tests/samples/pt-BR.mp3 +0 -0
- poly_server-0.1.0/tests/test_app.py +105 -0
- poly_server-0.1.0/tests/test_integration.py +22 -0
- poly_server-0.1.0/tests/test_listening.py +77 -0
- poly_server-0.1.0/tests/test_translate.py +34 -0
- poly_server-0.1.0/tests/test_vad.py +45 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
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
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
# Node / monorepo
|
|
210
|
+
node_modules/
|
|
211
|
+
*.tsbuildinfo
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Victor A. Guerra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: poly-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Speech language detection and offline UI translation server for Poly voice-driven interfaces.
|
|
5
|
+
Project-URL: Homepage, https://github.com/VictorAGuerra/Poly-SLID-Interface-Translator
|
|
6
|
+
Project-URL: Repository, https://github.com/VictorAGuerra/Poly-SLID-Interface-Translator
|
|
7
|
+
Project-URL: Issues, https://github.com/VictorAGuerra/Poly-SLID-Interface-Translator/issues
|
|
8
|
+
Author: Victor A. Guerra
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: accessibility,i18n,kiosk,language-detection,self-service,speech,translation,whisper
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Framework :: FastAPI
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
17
|
+
Classifier: Topic :: Software Development :: Internationalization
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: argostranslate>=1.9
|
|
20
|
+
Requires-Dist: fastapi>=0.115
|
|
21
|
+
Requires-Dist: faster-whisper>=1.1
|
|
22
|
+
Requires-Dist: numpy>=1.24
|
|
23
|
+
Requires-Dist: uvicorn[standard]>=0.30
|
|
24
|
+
Requires-Dist: webrtcvad-wheels>=2.0.14
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
28
|
+
Provides-Extra: mic
|
|
29
|
+
Requires-Dist: sounddevice>=0.5; extra == 'mic'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# poly-server
|
|
33
|
+
|
|
34
|
+
**English** · [Português](#português)
|
|
35
|
+
|
|
36
|
+
Speech language detection and offline UI translation server for
|
|
37
|
+
[Poly](https://www.npmjs.com/package/@swalay/poly-react), voice-driven
|
|
38
|
+
interfaces for self-service kiosks.
|
|
39
|
+
|
|
40
|
+
- **Speech → language** with [faster-whisper](https://github.com/SYSTRAN/faster-whisper).
|
|
41
|
+
- **UI translation** with [Argos Translate](https://github.com/argosopentech/argos-translate),
|
|
42
|
+
fully offline, with an English pivot when there's no direct language pair
|
|
43
|
+
and a persistent SQLite cache.
|
|
44
|
+
- **Two audio modes:** the server's own microphone (kiosk: screen and server on
|
|
45
|
+
the same machine) or audio streamed from the browser.
|
|
46
|
+
- Nothing leaves the device: no cloud APIs.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# CPU-only PyTorch first (Argos needs it); avoids ~3 GB of CUDA libraries
|
|
52
|
+
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
53
|
+
pip install "poly-server[mic]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The `mic` extra enables local microphone capture (needs PortAudio:
|
|
57
|
+
`sudo apt install libportaudio2` on Debian/Ubuntu). Skip it if audio only
|
|
58
|
+
comes from the browser.
|
|
59
|
+
|
|
60
|
+
## Run
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
poly-server serve # http://127.0.0.1:8000, local microphone
|
|
64
|
+
poly-server serve --no-mic # browser audio only
|
|
65
|
+
poly-server devices # list microphones
|
|
66
|
+
poly-server serve --mic-device 2
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Offline kiosks
|
|
70
|
+
|
|
71
|
+
Download everything once during installation, then run without network:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
poly-server download --base en --languages pt,es,fr,ar,ja,zh
|
|
75
|
+
poly-server serve --offline
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Configuration
|
|
79
|
+
|
|
80
|
+
Every option can be set with a `POLY_*` environment variable:
|
|
81
|
+
|
|
82
|
+
| Variable | Default | |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| `POLY_HOST` / `POLY_PORT` | `127.0.0.1` / `8000` | |
|
|
85
|
+
| `POLY_CORS_ORIGINS` | `*` | Comma-separated allowed origins. |
|
|
86
|
+
| `POLY_MIC` | `true` | Capture the local microphone. |
|
|
87
|
+
| `POLY_MIC_DEVICE` | system default | Input device index or name. |
|
|
88
|
+
| `POLY_WHISPER_MODEL` | `base` | `tiny`, `base`, `small`, `medium`, `large-v3`. |
|
|
89
|
+
| `POLY_WHISPER_DEVICE` | `auto` | `cpu`, `cuda`, `auto`. |
|
|
90
|
+
| `POLY_WHISPER_COMPUTE_TYPE` | `int8` | |
|
|
91
|
+
| `POLY_VAD_MODE` | `2` | 0 (lenient) to 3 (aggressive) voice detection. |
|
|
92
|
+
| `POLY_END_TRIGGER_MS` | `600` | Silence that ends an utterance. |
|
|
93
|
+
| `POLY_MAX_UTTERANCE_SEC` | `12` | |
|
|
94
|
+
| `POLY_CACHE_DIR` | `~/.cache/poly-server` | Models and translation cache. |
|
|
95
|
+
| `POLY_AUTO_DOWNLOAD` | `true` | Download translation packages on demand. |
|
|
96
|
+
|
|
97
|
+
## API
|
|
98
|
+
|
|
99
|
+
| Endpoint | |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `GET /health` | `{ ok, version, mic }` |
|
|
102
|
+
| `POST /i18n/auto-translate` | `{ source_lang, target_lang, texts: { key: text } }` → `{ target_lang, texts }`. Returns `422` with `code: "unsupported_language_pair"` when no translation exists. |
|
|
103
|
+
| `WS /ws` | Recognition events from the local microphone, broadcast to every client. Send `{"type":"config","listening":"manual"}` to listen only on demand, then `{"type":"listen","action":"start"\|"stop"}`; the server replies with `{"type":"listening","listening":bool}` and `{"type":"speech_start"}`. |
|
|
104
|
+
| `WS /ws/audio` | Send binary PCM16 LE mono 16 kHz; receive `{"type":"speech_start"}` / `{"type":"utterance_end"}` as speech starts and ends, then the recognition event. Text messages: `{"type":"flush"}` recognizes the speech in progress, `{"type":"reset"}` discards it. |
|
|
105
|
+
|
|
106
|
+
Event: `{ "type": "asr", "language": "pt", "confidence": 0.97, "text": "...", "latency_sec": 1.4 }`
|
|
107
|
+
|
|
108
|
+
### Embedding
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from poly_server import Settings, create_app
|
|
112
|
+
|
|
113
|
+
app = create_app(Settings(mic=False, whisper_model="small"))
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`create_app` also accepts custom `recognizer` and `translator` objects, to plug
|
|
117
|
+
in another speech model or translation service.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Português
|
|
126
|
+
|
|
127
|
+
Servidor de detecção do idioma falado e tradução offline de interfaces para o
|
|
128
|
+
Poly.
|
|
129
|
+
|
|
130
|
+
- **Fala → idioma** com faster-whisper.
|
|
131
|
+
- **Tradução** com Argos Translate, 100% offline, passando pelo inglês quando
|
|
132
|
+
não há pacote direto entre dois idiomas, e com cache em disco (SQLite).
|
|
133
|
+
- **Dois modos de áudio:** o microfone do próprio servidor (quiosque) ou o
|
|
134
|
+
áudio enviado pelo navegador.
|
|
135
|
+
- Nada sai do aparelho: nenhuma API na nuvem.
|
|
136
|
+
|
|
137
|
+
Instalação, execução e configuração: veja os comandos acima. Para quiosques
|
|
138
|
+
sem internet, rode `poly-server download` na instalação e depois
|
|
139
|
+
`poly-server serve --offline`.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# poly-server
|
|
2
|
+
|
|
3
|
+
**English** · [Português](#português)
|
|
4
|
+
|
|
5
|
+
Speech language detection and offline UI translation server for
|
|
6
|
+
[Poly](https://www.npmjs.com/package/@swalay/poly-react), voice-driven
|
|
7
|
+
interfaces for self-service kiosks.
|
|
8
|
+
|
|
9
|
+
- **Speech → language** with [faster-whisper](https://github.com/SYSTRAN/faster-whisper).
|
|
10
|
+
- **UI translation** with [Argos Translate](https://github.com/argosopentech/argos-translate),
|
|
11
|
+
fully offline, with an English pivot when there's no direct language pair
|
|
12
|
+
and a persistent SQLite cache.
|
|
13
|
+
- **Two audio modes:** the server's own microphone (kiosk: screen and server on
|
|
14
|
+
the same machine) or audio streamed from the browser.
|
|
15
|
+
- Nothing leaves the device: no cloud APIs.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# CPU-only PyTorch first (Argos needs it); avoids ~3 GB of CUDA libraries
|
|
21
|
+
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
22
|
+
pip install "poly-server[mic]"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The `mic` extra enables local microphone capture (needs PortAudio:
|
|
26
|
+
`sudo apt install libportaudio2` on Debian/Ubuntu). Skip it if audio only
|
|
27
|
+
comes from the browser.
|
|
28
|
+
|
|
29
|
+
## Run
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
poly-server serve # http://127.0.0.1:8000, local microphone
|
|
33
|
+
poly-server serve --no-mic # browser audio only
|
|
34
|
+
poly-server devices # list microphones
|
|
35
|
+
poly-server serve --mic-device 2
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Offline kiosks
|
|
39
|
+
|
|
40
|
+
Download everything once during installation, then run without network:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
poly-server download --base en --languages pt,es,fr,ar,ja,zh
|
|
44
|
+
poly-server serve --offline
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
Every option can be set with a `POLY_*` environment variable:
|
|
50
|
+
|
|
51
|
+
| Variable | Default | |
|
|
52
|
+
| --- | --- | --- |
|
|
53
|
+
| `POLY_HOST` / `POLY_PORT` | `127.0.0.1` / `8000` | |
|
|
54
|
+
| `POLY_CORS_ORIGINS` | `*` | Comma-separated allowed origins. |
|
|
55
|
+
| `POLY_MIC` | `true` | Capture the local microphone. |
|
|
56
|
+
| `POLY_MIC_DEVICE` | system default | Input device index or name. |
|
|
57
|
+
| `POLY_WHISPER_MODEL` | `base` | `tiny`, `base`, `small`, `medium`, `large-v3`. |
|
|
58
|
+
| `POLY_WHISPER_DEVICE` | `auto` | `cpu`, `cuda`, `auto`. |
|
|
59
|
+
| `POLY_WHISPER_COMPUTE_TYPE` | `int8` | |
|
|
60
|
+
| `POLY_VAD_MODE` | `2` | 0 (lenient) to 3 (aggressive) voice detection. |
|
|
61
|
+
| `POLY_END_TRIGGER_MS` | `600` | Silence that ends an utterance. |
|
|
62
|
+
| `POLY_MAX_UTTERANCE_SEC` | `12` | |
|
|
63
|
+
| `POLY_CACHE_DIR` | `~/.cache/poly-server` | Models and translation cache. |
|
|
64
|
+
| `POLY_AUTO_DOWNLOAD` | `true` | Download translation packages on demand. |
|
|
65
|
+
|
|
66
|
+
## API
|
|
67
|
+
|
|
68
|
+
| Endpoint | |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| `GET /health` | `{ ok, version, mic }` |
|
|
71
|
+
| `POST /i18n/auto-translate` | `{ source_lang, target_lang, texts: { key: text } }` → `{ target_lang, texts }`. Returns `422` with `code: "unsupported_language_pair"` when no translation exists. |
|
|
72
|
+
| `WS /ws` | Recognition events from the local microphone, broadcast to every client. Send `{"type":"config","listening":"manual"}` to listen only on demand, then `{"type":"listen","action":"start"\|"stop"}`; the server replies with `{"type":"listening","listening":bool}` and `{"type":"speech_start"}`. |
|
|
73
|
+
| `WS /ws/audio` | Send binary PCM16 LE mono 16 kHz; receive `{"type":"speech_start"}` / `{"type":"utterance_end"}` as speech starts and ends, then the recognition event. Text messages: `{"type":"flush"}` recognizes the speech in progress, `{"type":"reset"}` discards it. |
|
|
74
|
+
|
|
75
|
+
Event: `{ "type": "asr", "language": "pt", "confidence": 0.97, "text": "...", "latency_sec": 1.4 }`
|
|
76
|
+
|
|
77
|
+
### Embedding
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from poly_server import Settings, create_app
|
|
81
|
+
|
|
82
|
+
app = create_app(Settings(mic=False, whisper_model="small"))
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`create_app` also accepts custom `recognizer` and `translator` objects, to plug
|
|
86
|
+
in another speech model or translation service.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Português
|
|
95
|
+
|
|
96
|
+
Servidor de detecção do idioma falado e tradução offline de interfaces para o
|
|
97
|
+
Poly.
|
|
98
|
+
|
|
99
|
+
- **Fala → idioma** com faster-whisper.
|
|
100
|
+
- **Tradução** com Argos Translate, 100% offline, passando pelo inglês quando
|
|
101
|
+
não há pacote direto entre dois idiomas, e com cache em disco (SQLite).
|
|
102
|
+
- **Dois modos de áudio:** o microfone do próprio servidor (quiosque) ou o
|
|
103
|
+
áudio enviado pelo navegador.
|
|
104
|
+
- Nada sai do aparelho: nenhuma API na nuvem.
|
|
105
|
+
|
|
106
|
+
Instalação, execução e configuração: veja os comandos acima. Para quiosques
|
|
107
|
+
sem internet, rode `poly-server download` na instalação e depois
|
|
108
|
+
`poly-server serve --offline`.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "poly-server"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Speech language detection and offline UI translation server for Poly voice-driven interfaces."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Victor A. Guerra" }]
|
|
14
|
+
keywords = ["i18n", "translation", "speech", "language-detection", "whisper", "kiosk", "self-service", "accessibility"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Framework :: FastAPI",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Multimedia :: Sound/Audio :: Speech",
|
|
21
|
+
"Topic :: Software Development :: Internationalization",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"fastapi>=0.115",
|
|
25
|
+
"uvicorn[standard]>=0.30",
|
|
26
|
+
"faster-whisper>=1.1",
|
|
27
|
+
"argostranslate>=1.9",
|
|
28
|
+
"webrtcvad-wheels>=2.0.14",
|
|
29
|
+
"numpy>=1.24",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
mic = ["sounddevice>=0.5"]
|
|
34
|
+
dev = ["pytest>=8", "httpx>=0.27"]
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
poly-server = "poly_server.cli:main"
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/VictorAGuerra/Poly-SLID-Interface-Translator"
|
|
41
|
+
Repository = "https://github.com/VictorAGuerra/Poly-SLID-Interface-Translator"
|
|
42
|
+
Issues = "https://github.com/VictorAGuerra/Poly-SLID-Interface-Translator/issues"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
packages = ["src/poly_server"]
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
testpaths = ["tests"]
|
|
49
|
+
markers = ["integration: loads real models (slow, needs network on first run)"]
|
|
50
|
+
addopts = "-m 'not integration'"
|