macos-say-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.
@@ -0,0 +1,52 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ push:
13
+ tags: [ 'v*.*.*' ]
14
+ workflow_dispatch:
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ release-build-and-publish-pypi:
21
+ runs-on: ubuntu-latest
22
+
23
+ environment:
24
+ name: pypi
25
+
26
+ steps:
27
+ - uses: actions/checkout@v6
28
+
29
+ - name: Install uv
30
+ uses: astral-sh/setup-uv@v7
31
+
32
+ - name: "Set up Python"
33
+ uses: actions/setup-python@v6
34
+ with:
35
+ python-version-file: "pyproject.toml"
36
+
37
+ - name: Install the project
38
+ run: uv sync --all-groups
39
+
40
+ - name: Build release distributions
41
+ run: uv build
42
+
43
+ - name: Upload distributions
44
+ uses: actions/upload-artifact@v7
45
+ with:
46
+ name: release-dists
47
+ path: dist/
48
+
49
+ - name: Publish PyPI
50
+ env:
51
+ UV_PUBLISH_TOKEN: ${{ secrets.UV_PUBLISH_TOKEN }}
52
+ run: uv publish
@@ -0,0 +1,218 @@
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
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lanbao
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,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: macos-say-server
3
+ Version: 0.1.0
4
+ Summary: Expose macOS say as an HTTP server that provides text-to-speech audio generation.
5
+ License-File: LICENSE
6
+ Requires-Python: >=3.9
7
+ Requires-Dist: fastapi[standard]>=0.116.0
8
+ Requires-Dist: uvicorn>=0.35.0
9
+ Description-Content-Type: text/markdown
10
+
11
+ # macos-say-server
12
+
13
+ Expose macOS say as an HTTP server that provides text-to-speech audio generation.
14
+
15
+ ## Features
16
+
17
+ - `GET /health` for liveness checks.
18
+ - `GET /voices` to list the voices available from `say -v '?'`.
19
+ - `GET /cache/stats` to inspect current cache usage and limits.
20
+ - `GET /speak?text=...&voice=...` to return AIFF audio directly.
21
+ - `POST /speak` with JSON `{ "text": "...", "voice": "..." }` to return AIFF audio.
22
+ - Disk-backed AIFF cache keyed by `text + voice`, with lazy TTL cleanup.
23
+
24
+ ## Run
25
+
26
+ ```bash
27
+ uv sync
28
+ uv run macos-say-server
29
+ ```
30
+
31
+ The server binds to `127.0.0.1:2576` by default.
32
+
33
+ Use startup arguments to override bind settings:
34
+
35
+ ```bash
36
+ uv run macos-say-server --host 127.0.0.1 --port 2576
37
+ ```
38
+
39
+ You can also run the package module directly:
40
+
41
+ ```bash
42
+ uv run python -m macos_say_server --host 127.0.0.1 --port 2576
43
+ ```
44
+
45
+ ## Build
46
+
47
+ ```bash
48
+ uv build
49
+ ```
50
+
51
+ ## Cache
52
+
53
+ The service stores generated audio under `.cache/audio` by default.
54
+
55
+ - Cache key: hash of `text + voice`
56
+ - Expiration: `CACHE_TTL_SECONDS`, default `86400` seconds
57
+ - Cleanup: lazy cleanup during requests, at most once per `CACHE_CLEANUP_INTERVAL_SECONDS`, default `300` seconds
58
+ - On cache hit, the file timestamp is refreshed, so TTL is sliding rather than fixed from first generation
59
+ - Capacity control: optional LRU-style pruning using file modification time
60
+ - File count limit: `CACHE_MAX_FILES`, default `0` meaning unlimited
61
+ - Total size limit: `CACHE_MAX_BYTES`, default `0` meaning unlimited
62
+
63
+ When a cache limit is configured, the oldest entries are removed first. Because cache hits refresh the file timestamp, frequently used items stay warm and cold items are evicted first.
64
+
65
+ `GET /cache/stats` returns:
66
+
67
+ - `cache_dir` and whether it currently exists
68
+ - `total_files` and `total_bytes`
69
+ - `expired_files` under the current TTL view
70
+ - configured `ttl_seconds`, cleanup interval, and capacity limits
71
+ - oldest and newest cache entry timestamps
72
+
73
+ Startup arguments:
74
+
75
+ ```bash
76
+ uv run macos-say-server \
77
+ --cache-dir .cache/audio \
78
+ --cache-ttl-seconds 86400 \
79
+ --cache-cleanup-interval-seconds 300 \
80
+ --cache-max-files 0 \
81
+ --cache-max-bytes 0
82
+ ```
83
+
84
+ ## Examples
85
+
86
+ ```bash
87
+ curl http://127.0.0.1:2576/health
88
+ curl http://127.0.0.1:2576/voices
89
+ curl http://127.0.0.1:2576/cache/stats
90
+ curl -G http://127.0.0.1:2576/speak --data-urlencode "text=hello from macos say server" --output speech.aiff
91
+ curl -i -G http://127.0.0.1:2576/speak --data-urlencode "text=hello from macos say server" --output speech.aiff
92
+ curl -X POST http://127.0.0.1:2576/speak \
93
+ -H "content-type: application/json" \
94
+ -d '{"text":"hello from json","voice":"Samantha"}' \
95
+ --output speech.aiff
96
+ ```
97
+
98
+ If you inspect response headers, `X-Cache: MISS` means the file was newly synthesized, and `X-Cache: HIT` means it was served from cache.
@@ -0,0 +1,88 @@
1
+ # macos-say-server
2
+
3
+ Expose macOS say as an HTTP server that provides text-to-speech audio generation.
4
+
5
+ ## Features
6
+
7
+ - `GET /health` for liveness checks.
8
+ - `GET /voices` to list the voices available from `say -v '?'`.
9
+ - `GET /cache/stats` to inspect current cache usage and limits.
10
+ - `GET /speak?text=...&voice=...` to return AIFF audio directly.
11
+ - `POST /speak` with JSON `{ "text": "...", "voice": "..." }` to return AIFF audio.
12
+ - Disk-backed AIFF cache keyed by `text + voice`, with lazy TTL cleanup.
13
+
14
+ ## Run
15
+
16
+ ```bash
17
+ uv sync
18
+ uv run macos-say-server
19
+ ```
20
+
21
+ The server binds to `127.0.0.1:2576` by default.
22
+
23
+ Use startup arguments to override bind settings:
24
+
25
+ ```bash
26
+ uv run macos-say-server --host 127.0.0.1 --port 2576
27
+ ```
28
+
29
+ You can also run the package module directly:
30
+
31
+ ```bash
32
+ uv run python -m macos_say_server --host 127.0.0.1 --port 2576
33
+ ```
34
+
35
+ ## Build
36
+
37
+ ```bash
38
+ uv build
39
+ ```
40
+
41
+ ## Cache
42
+
43
+ The service stores generated audio under `.cache/audio` by default.
44
+
45
+ - Cache key: hash of `text + voice`
46
+ - Expiration: `CACHE_TTL_SECONDS`, default `86400` seconds
47
+ - Cleanup: lazy cleanup during requests, at most once per `CACHE_CLEANUP_INTERVAL_SECONDS`, default `300` seconds
48
+ - On cache hit, the file timestamp is refreshed, so TTL is sliding rather than fixed from first generation
49
+ - Capacity control: optional LRU-style pruning using file modification time
50
+ - File count limit: `CACHE_MAX_FILES`, default `0` meaning unlimited
51
+ - Total size limit: `CACHE_MAX_BYTES`, default `0` meaning unlimited
52
+
53
+ When a cache limit is configured, the oldest entries are removed first. Because cache hits refresh the file timestamp, frequently used items stay warm and cold items are evicted first.
54
+
55
+ `GET /cache/stats` returns:
56
+
57
+ - `cache_dir` and whether it currently exists
58
+ - `total_files` and `total_bytes`
59
+ - `expired_files` under the current TTL view
60
+ - configured `ttl_seconds`, cleanup interval, and capacity limits
61
+ - oldest and newest cache entry timestamps
62
+
63
+ Startup arguments:
64
+
65
+ ```bash
66
+ uv run macos-say-server \
67
+ --cache-dir .cache/audio \
68
+ --cache-ttl-seconds 86400 \
69
+ --cache-cleanup-interval-seconds 300 \
70
+ --cache-max-files 0 \
71
+ --cache-max-bytes 0
72
+ ```
73
+
74
+ ## Examples
75
+
76
+ ```bash
77
+ curl http://127.0.0.1:2576/health
78
+ curl http://127.0.0.1:2576/voices
79
+ curl http://127.0.0.1:2576/cache/stats
80
+ curl -G http://127.0.0.1:2576/speak --data-urlencode "text=hello from macos say server" --output speech.aiff
81
+ curl -i -G http://127.0.0.1:2576/speak --data-urlencode "text=hello from macos say server" --output speech.aiff
82
+ curl -X POST http://127.0.0.1:2576/speak \
83
+ -H "content-type: application/json" \
84
+ -d '{"text":"hello from json","voice":"Samantha"}' \
85
+ --output speech.aiff
86
+ ```
87
+
88
+ If you inspect response headers, `X-Cache: MISS` means the file was newly synthesized, and `X-Cache: HIT` means it was served from cache.
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "macos-say-server"
7
+ version = "0.1.0"
8
+ description = "Expose macOS say as an HTTP server that provides text-to-speech audio generation."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ "fastapi[standard]>=0.116.0",
13
+ "uvicorn>=0.35.0"
14
+ ]
15
+
16
+ [project.scripts]
17
+ macos-say-server = "macos_say_server.cli:main"
18
+
19
+ [tool.hatch.build.targets.wheel]
20
+ packages = ["src/macos_say_server"]
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+ from .server import app
3
+
4
+ __all__ = ["app", "main"]
@@ -0,0 +1,5 @@
1
+ from .cli import main
2
+
3
+
4
+ if __name__ == "__main__":
5
+ raise SystemExit(main())
@@ -0,0 +1,36 @@
1
+ import argparse
2
+ from pathlib import Path
3
+
4
+ import uvicorn
5
+
6
+ from .server import app, configure_cache
7
+
8
+
9
+ def build_parser() -> argparse.ArgumentParser:
10
+ parser = argparse.ArgumentParser(description="Run the macOS say HTTP server.")
11
+ parser.add_argument("--host", default="127.0.0.1", help="Host interface to bind to")
12
+ parser.add_argument("--port", type=int, default=2576, help="Port to listen on")
13
+ parser.add_argument("--cache-dir", type=Path, default=Path(".cache/audio"), help="Directory for cached AIFF files")
14
+ parser.add_argument("--cache-ttl-seconds", type=int, default=86400, help="Cache TTL in seconds; 0 disables reuse")
15
+ parser.add_argument(
16
+ "--cache-cleanup-interval-seconds",
17
+ type=int,
18
+ default=300,
19
+ help="Minimum seconds between lazy cleanup passes",
20
+ )
21
+ parser.add_argument("--cache-max-files", type=int, default=0, help="Maximum cached files; 0 means unlimited")
22
+ parser.add_argument("--cache-max-bytes", type=int, default=0, help="Maximum cached bytes; 0 means unlimited")
23
+ return parser
24
+
25
+
26
+ def main() -> int:
27
+ args = build_parser().parse_args()
28
+ configure_cache(
29
+ cache_dir=args.cache_dir,
30
+ ttl_seconds=args.cache_ttl_seconds,
31
+ cleanup_interval_seconds=args.cache_cleanup_interval_seconds,
32
+ max_files=args.cache_max_files,
33
+ max_bytes=args.cache_max_bytes,
34
+ )
35
+ uvicorn.run(app, host=args.host, port=args.port)
36
+ return 0