talkaty 1.2.1__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.
- talkaty-1.2.1/LICENSE +21 -0
- talkaty-1.2.1/PKG-INFO +140 -0
- talkaty-1.2.1/README.md +102 -0
- talkaty-1.2.1/pyproject.toml +53 -0
- talkaty-1.2.1/setup.cfg +4 -0
- talkaty-1.2.1/src/talkaty/__about__.py +1 -0
- talkaty-1.2.1/src/talkaty/__init__.py +5 -0
- talkaty-1.2.1/src/talkaty/audio.py +70 -0
- talkaty-1.2.1/src/talkaty/backends/base.py +33 -0
- talkaty-1.2.1/src/talkaty/backends/edge_tts.py +54 -0
- talkaty-1.2.1/src/talkaty/backends/kittentts.py +54 -0
- talkaty-1.2.1/src/talkaty/backends/piper.py +60 -0
- talkaty-1.2.1/src/talkaty/cli.py +197 -0
- talkaty-1.2.1/src/talkaty/config.py +22 -0
- talkaty-1.2.1/src/talkaty/mcp_server.py +213 -0
- talkaty-1.2.1/src/talkaty/pipeline.py +128 -0
- talkaty-1.2.1/src/talkaty/script.py +146 -0
- talkaty-1.2.1/src/talkaty/ssml.py +113 -0
- talkaty-1.2.1/src/talkaty/voices.py +143 -0
- talkaty-1.2.1/src/talkaty.egg-info/PKG-INFO +140 -0
- talkaty-1.2.1/src/talkaty.egg-info/SOURCES.txt +30 -0
- talkaty-1.2.1/src/talkaty.egg-info/dependency_links.txt +1 -0
- talkaty-1.2.1/src/talkaty.egg-info/entry_points.txt +2 -0
- talkaty-1.2.1/src/talkaty.egg-info/requires.txt +21 -0
- talkaty-1.2.1/src/talkaty.egg-info/top_level.txt +1 -0
- talkaty-1.2.1/tests/test_audio.py +48 -0
- talkaty-1.2.1/tests/test_backends.py +92 -0
- talkaty-1.2.1/tests/test_batch.py +30 -0
- talkaty-1.2.1/tests/test_cli.py +34 -0
- talkaty-1.2.1/tests/test_pipeline.py +117 -0
- talkaty-1.2.1/tests/test_script.py +70 -0
- talkaty-1.2.1/tests/test_ssml.py +69 -0
talkaty-1.2.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dream-Pixels-Forge
|
|
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.
|
talkaty-1.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: talkaty
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Terminal-native TTS voiceover tool — script.md to audio in any accent, via CLI or MCP.
|
|
5
|
+
Author: Dream-Pixels-Forge
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: cli,tts,voiceover,mcp,edge-tts,kittentts
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
15
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: edge-tts>=6.0.0
|
|
20
|
+
Requires-Dist: httpx>=0.25.0
|
|
21
|
+
Requires-Dist: pydantic>=2.0.0
|
|
22
|
+
Requires-Dist: pyyaml>=6.0.1
|
|
23
|
+
Requires-Dist: typer>=0.12.0
|
|
24
|
+
Requires-Dist: rich>=13.0.0
|
|
25
|
+
Provides-Extra: kittentts
|
|
26
|
+
Requires-Dist: kittentts>=0.1.0; extra == "kittentts"
|
|
27
|
+
Provides-Extra: piper
|
|
28
|
+
Requires-Dist: piper-tts>=1.8.0; extra == "piper"
|
|
29
|
+
Requires-Dist: numpy>=1.24; extra == "piper"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff>=0.8.0; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy>=1.8.0; extra == "dev"
|
|
35
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# talkaty
|
|
40
|
+
|
|
41
|
+
Terminal-native TTS voiceover tool. Turn a `script.md` (plus optional brief) into polished voiceover audio in any accent, using open-source TTS backends. Exposes both a CLI and an MCP stdio server for coding agents.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install -e . # edge-tts backend (default)
|
|
47
|
+
pip install -e .[kittentts] # add kittenTTS local offline fallback
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## CLI
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Generate voiceover from a script.md (default: smooth female, US, edge-tts)
|
|
54
|
+
talkaty generate script.md
|
|
55
|
+
|
|
56
|
+
# Choose a persona and accent
|
|
57
|
+
talkaty generate script.md --voice "alpha male" --accent US
|
|
58
|
+
|
|
59
|
+
# Pitch, speed, and subtitles
|
|
60
|
+
talkaty generate script.md --pitch 2 --speed 1.2 --subtitles
|
|
61
|
+
|
|
62
|
+
# Brief-driven accent auto-selection (brief mentions "Nigerian" → NG voice)
|
|
63
|
+
talkaty generate script.md --brief brief.txt
|
|
64
|
+
|
|
65
|
+
# List available personas/voices
|
|
66
|
+
talkaty voices
|
|
67
|
+
|
|
68
|
+
# Preview a short sample (no script file needed)
|
|
69
|
+
talkaty preview "Hello world" --voice "alpha male"
|
|
70
|
+
|
|
71
|
+
# Batch a directory of scripts
|
|
72
|
+
talkaty batch scripts/ out/
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Personas
|
|
76
|
+
|
|
77
|
+
| Persona | Description | Accent |
|
|
78
|
+
|---------|-------------|--------|
|
|
79
|
+
| alpha male | Bold, authoritative male voice | US |
|
|
80
|
+
| smooth female | Warm, friendly female voice | US |
|
|
81
|
+
| warm narrator | Storytelling female voice | UK |
|
|
82
|
+
| energetic | High-energy voice for ads/hype | US |
|
|
83
|
+
| calm | Calm male voice for meditation/ASMR | AU |
|
|
84
|
+
| nigerian narrator | Nigerian English storytelling voice | NG |
|
|
85
|
+
| french narrator | French storytelling voice | FR |
|
|
86
|
+
| chinese narrator | Mandarin Chinese storytelling voice | ZH |
|
|
87
|
+
| narrator | Deep, mysterious storyteller for documentaries | US |
|
|
88
|
+
| deep french narrator | Deep, mysterious French storyteller for documentaries | FR |
|
|
89
|
+
| hindi narrator | Hindi storytelling voice | HI |
|
|
90
|
+
| spanish narrator | Spanish storytelling voice | ES |
|
|
91
|
+
| german narrator | German storytelling voice | DE |
|
|
92
|
+
|
|
93
|
+
## Backends
|
|
94
|
+
|
|
95
|
+
- `edge-tts` (default): 400+ voices, many accents, free, no API key
|
|
96
|
+
- `kitten-tts`: local, offline fallback (`pip install talkaty[kittentts]`)
|
|
97
|
+
- `piper`: local, offline backend using `.onnx` voice models (`pip install talkaty[piper]`)
|
|
98
|
+
|
|
99
|
+
## MCP
|
|
100
|
+
|
|
101
|
+
talkaty runs as an MCP stdio server exposing `tts_generate`, `list_voices`, `list_personas`, and `preview`. Connect it to any MCP-compatible coding agent to generate voiceover from within your agent loop.
|
|
102
|
+
|
|
103
|
+
Example MCP call (`tts_generate`):
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"script_path": "script.md",
|
|
107
|
+
"brief_path": "brief.txt",
|
|
108
|
+
"voice": "smooth female",
|
|
109
|
+
"accent": "US",
|
|
110
|
+
"backend": "edge-tts"
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Outputs
|
|
115
|
+
|
|
116
|
+
- Audio: MP3 (default), WAV
|
|
117
|
+
- Subtitles: SRT, VTT (via `--subtitles`)
|
|
118
|
+
- Metadata: sidecar `.json` with voice, backend, duration, settings
|
|
119
|
+
|
|
120
|
+
## SSML-lite markup
|
|
121
|
+
|
|
122
|
+
Add fine-grained control inside `script.md` with SSML-lite tags:
|
|
123
|
+
|
|
124
|
+
| Tag | Effect |
|
|
125
|
+
|-----|--------|
|
|
126
|
+
| `<break time='1s'/>` | Pause for 1 second (also `500ms`, `2s`) |
|
|
127
|
+
| `<emphasis>text</emphasis>` | Emphasize text (pitch boost) |
|
|
128
|
+
| `<pitch>+2</pitch>` | Set pitch in semitones for following text (negative = deeper) |
|
|
129
|
+
|
|
130
|
+
Example:
|
|
131
|
+
```markdown
|
|
132
|
+
Hello.<break time='1s'/> <emphasis>Listen closely</emphasis> now.
|
|
133
|
+
<pitch>+2</pitch>This is higher pitched.
|
|
134
|
+
<pitch>-2</pitch>This is deeper.
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## CI
|
|
138
|
+
|
|
139
|
+
`mypy`, `ruff`, `ruff format`, and `pytest` run on every push/PR via GitHub Actions.
|
|
140
|
+
|
talkaty-1.2.1/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# talkaty
|
|
2
|
+
|
|
3
|
+
Terminal-native TTS voiceover tool. Turn a `script.md` (plus optional brief) into polished voiceover audio in any accent, using open-source TTS backends. Exposes both a CLI and an MCP stdio server for coding agents.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install -e . # edge-tts backend (default)
|
|
9
|
+
pip install -e .[kittentts] # add kittenTTS local offline fallback
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## CLI
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Generate voiceover from a script.md (default: smooth female, US, edge-tts)
|
|
16
|
+
talkaty generate script.md
|
|
17
|
+
|
|
18
|
+
# Choose a persona and accent
|
|
19
|
+
talkaty generate script.md --voice "alpha male" --accent US
|
|
20
|
+
|
|
21
|
+
# Pitch, speed, and subtitles
|
|
22
|
+
talkaty generate script.md --pitch 2 --speed 1.2 --subtitles
|
|
23
|
+
|
|
24
|
+
# Brief-driven accent auto-selection (brief mentions "Nigerian" → NG voice)
|
|
25
|
+
talkaty generate script.md --brief brief.txt
|
|
26
|
+
|
|
27
|
+
# List available personas/voices
|
|
28
|
+
talkaty voices
|
|
29
|
+
|
|
30
|
+
# Preview a short sample (no script file needed)
|
|
31
|
+
talkaty preview "Hello world" --voice "alpha male"
|
|
32
|
+
|
|
33
|
+
# Batch a directory of scripts
|
|
34
|
+
talkaty batch scripts/ out/
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Personas
|
|
38
|
+
|
|
39
|
+
| Persona | Description | Accent |
|
|
40
|
+
|---------|-------------|--------|
|
|
41
|
+
| alpha male | Bold, authoritative male voice | US |
|
|
42
|
+
| smooth female | Warm, friendly female voice | US |
|
|
43
|
+
| warm narrator | Storytelling female voice | UK |
|
|
44
|
+
| energetic | High-energy voice for ads/hype | US |
|
|
45
|
+
| calm | Calm male voice for meditation/ASMR | AU |
|
|
46
|
+
| nigerian narrator | Nigerian English storytelling voice | NG |
|
|
47
|
+
| french narrator | French storytelling voice | FR |
|
|
48
|
+
| chinese narrator | Mandarin Chinese storytelling voice | ZH |
|
|
49
|
+
| narrator | Deep, mysterious storyteller for documentaries | US |
|
|
50
|
+
| deep french narrator | Deep, mysterious French storyteller for documentaries | FR |
|
|
51
|
+
| hindi narrator | Hindi storytelling voice | HI |
|
|
52
|
+
| spanish narrator | Spanish storytelling voice | ES |
|
|
53
|
+
| german narrator | German storytelling voice | DE |
|
|
54
|
+
|
|
55
|
+
## Backends
|
|
56
|
+
|
|
57
|
+
- `edge-tts` (default): 400+ voices, many accents, free, no API key
|
|
58
|
+
- `kitten-tts`: local, offline fallback (`pip install talkaty[kittentts]`)
|
|
59
|
+
- `piper`: local, offline backend using `.onnx` voice models (`pip install talkaty[piper]`)
|
|
60
|
+
|
|
61
|
+
## MCP
|
|
62
|
+
|
|
63
|
+
talkaty runs as an MCP stdio server exposing `tts_generate`, `list_voices`, `list_personas`, and `preview`. Connect it to any MCP-compatible coding agent to generate voiceover from within your agent loop.
|
|
64
|
+
|
|
65
|
+
Example MCP call (`tts_generate`):
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"script_path": "script.md",
|
|
69
|
+
"brief_path": "brief.txt",
|
|
70
|
+
"voice": "smooth female",
|
|
71
|
+
"accent": "US",
|
|
72
|
+
"backend": "edge-tts"
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Outputs
|
|
77
|
+
|
|
78
|
+
- Audio: MP3 (default), WAV
|
|
79
|
+
- Subtitles: SRT, VTT (via `--subtitles`)
|
|
80
|
+
- Metadata: sidecar `.json` with voice, backend, duration, settings
|
|
81
|
+
|
|
82
|
+
## SSML-lite markup
|
|
83
|
+
|
|
84
|
+
Add fine-grained control inside `script.md` with SSML-lite tags:
|
|
85
|
+
|
|
86
|
+
| Tag | Effect |
|
|
87
|
+
|-----|--------|
|
|
88
|
+
| `<break time='1s'/>` | Pause for 1 second (also `500ms`, `2s`) |
|
|
89
|
+
| `<emphasis>text</emphasis>` | Emphasize text (pitch boost) |
|
|
90
|
+
| `<pitch>+2</pitch>` | Set pitch in semitones for following text (negative = deeper) |
|
|
91
|
+
|
|
92
|
+
Example:
|
|
93
|
+
```markdown
|
|
94
|
+
Hello.<break time='1s'/> <emphasis>Listen closely</emphasis> now.
|
|
95
|
+
<pitch>+2</pitch>This is higher pitched.
|
|
96
|
+
<pitch>-2</pitch>This is deeper.
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## CI
|
|
100
|
+
|
|
101
|
+
`mypy`, `ruff`, `ruff format`, and `pytest` run on every push/PR via GitHub Actions.
|
|
102
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "talkaty"
|
|
7
|
+
version = "1.2.1"
|
|
8
|
+
description = "Terminal-native TTS voiceover tool — script.md to audio in any accent, via CLI or MCP."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "Dream-Pixels-Forge" }]
|
|
13
|
+
keywords = ["cli", "tts", "voiceover", "mcp", "edge-tts", "kittentts"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: POSIX :: Linux",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Topic :: Multimedia :: Sound/Audio :: Speech",
|
|
22
|
+
"Topic :: Software Development :: Version Control :: Git",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
dependencies = [
|
|
26
|
+
"edge-tts>=6.0.0",
|
|
27
|
+
"httpx>=0.25.0",
|
|
28
|
+
"pydantic>=2.0.0",
|
|
29
|
+
"pyyaml>=6.0.1",
|
|
30
|
+
"typer>=0.12.0",
|
|
31
|
+
"rich>=13.0.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
kittentts = ["kittentts>=0.1.0"]
|
|
36
|
+
piper = ["piper-tts>=1.8.0", "numpy>=1.24"]
|
|
37
|
+
dev = [
|
|
38
|
+
"pytest>=7.0",
|
|
39
|
+
"pytest-asyncio>=0.21.0",
|
|
40
|
+
"ruff>=0.8.0",
|
|
41
|
+
"mypy>=1.8.0",
|
|
42
|
+
"build>=1.0.0",
|
|
43
|
+
"twine>=4.0.0",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.scripts]
|
|
47
|
+
talkaty = "talkaty.cli:main"
|
|
48
|
+
|
|
49
|
+
[tool.ruff]
|
|
50
|
+
line-length = 100
|
|
51
|
+
|
|
52
|
+
[tool.ruff.lint]
|
|
53
|
+
ignore = ["B008", "ASYNC230"]
|
talkaty-1.2.1/setup.cfg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Audio output: write MP3/WAV, compute duration, write SRT/VTT subtitles."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class AudioResult:
|
|
10
|
+
path: str
|
|
11
|
+
duration_seconds: float
|
|
12
|
+
voice_used: str
|
|
13
|
+
backend_used: str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def write_audio(path: str, data: bytes, fmt: str = "mp3") -> str:
|
|
17
|
+
"""Write raw audio bytes to `path`. Returns the path written."""
|
|
18
|
+
with open(path, "wb") as fh:
|
|
19
|
+
fh.write(data)
|
|
20
|
+
return path
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def estimate_duration_ms(segments: list, words_per_minute: int = 150) -> int:
|
|
24
|
+
"""Rough duration estimate from segment text (fallback when backend doesn't report)."""
|
|
25
|
+
total_chars = sum(len(seg.text) for seg in segments)
|
|
26
|
+
# ~5 chars per word average
|
|
27
|
+
words = total_chars / 5.0
|
|
28
|
+
minutes = words / words_per_minute
|
|
29
|
+
return int(minutes * 60 * 1000)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def write_srt(path: str, segments: list, start_ms: int = 0) -> str:
|
|
33
|
+
"""Write an SRT subtitle file from segments with start/end ms."""
|
|
34
|
+
offset = start_ms
|
|
35
|
+
with open(path, "w", encoding="utf-8") as fh:
|
|
36
|
+
for i, seg in enumerate(segments, 1):
|
|
37
|
+
start = offset + (seg.start_ms or 0)
|
|
38
|
+
end = offset + (seg.end_ms or start + 2000)
|
|
39
|
+
fh.write(f"{i}\n")
|
|
40
|
+
fh.write(f"{_fmt_ts(start)} --> {_fmt_ts(end)}\n")
|
|
41
|
+
fh.write(f"{seg.text}\n\n")
|
|
42
|
+
return path
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def write_vtt(path: str, segments: list, start_ms: int = 0) -> str:
|
|
46
|
+
"""Write a VTT subtitle file."""
|
|
47
|
+
offset = start_ms
|
|
48
|
+
with open(path, "w", encoding="utf-8") as fh:
|
|
49
|
+
fh.write("WEBVTT\n\n")
|
|
50
|
+
for i, seg in enumerate(segments, 1):
|
|
51
|
+
start = offset + (seg.start_ms or 0)
|
|
52
|
+
end = offset + (seg.end_ms or start + 2000)
|
|
53
|
+
fh.write(f"{i}\n")
|
|
54
|
+
fh.write(f"{_fmt_vtt_ts(start)} --> {_fmt_vtt_ts(end)}\n")
|
|
55
|
+
fh.write(f"{seg.text}\n\n")
|
|
56
|
+
return path
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _fmt_ts(ms: int) -> str:
|
|
60
|
+
total = ms // 1000
|
|
61
|
+
h, rem = divmod(total, 3600)
|
|
62
|
+
m, s = divmod(rem, 60)
|
|
63
|
+
return f"{h:02d}:{m:02d}:{s:02d},{ms % 1000:03d}"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _fmt_vtt_ts(ms: int) -> str:
|
|
67
|
+
total = ms // 1000
|
|
68
|
+
h, rem = divmod(total, 3600)
|
|
69
|
+
m, s = divmod(rem, 60)
|
|
70
|
+
return f"{h:02d}:{m:02d}:{s:02d}.{ms % 1000:03d}"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Abstract base class for TTS backends."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True)
|
|
8
|
+
class VoiceInfo:
|
|
9
|
+
id: str
|
|
10
|
+
name: str
|
|
11
|
+
accent: str
|
|
12
|
+
gender: str
|
|
13
|
+
backend: str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TTSBackend(ABC):
|
|
17
|
+
"""A TTS backend turns text + voice controls into audio bytes."""
|
|
18
|
+
|
|
19
|
+
name: str
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
async def synthesize(
|
|
23
|
+
self,
|
|
24
|
+
text: str,
|
|
25
|
+
voice: str,
|
|
26
|
+
pitch: float | str = 0.0,
|
|
27
|
+
speed: float = 1.0,
|
|
28
|
+
) -> bytes:
|
|
29
|
+
"""Synthesize `text` with `voice`, returning audio bytes (MP3)."""
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def list_voices(self) -> list[VoiceInfo]:
|
|
33
|
+
"""List available voices for this backend."""
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""edge-tts backend — Microsoft Edge TTS, free, 400+ voices, many accents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from talkaty.backends.base import TTSBackend, VoiceInfo
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class EdgeTTS(TTSBackend):
|
|
9
|
+
name = "edge-tts"
|
|
10
|
+
|
|
11
|
+
async def synthesize(
|
|
12
|
+
self,
|
|
13
|
+
text: str,
|
|
14
|
+
voice: str,
|
|
15
|
+
pitch: float | str = 0.0,
|
|
16
|
+
speed: float = 1.0,
|
|
17
|
+
) -> bytes:
|
|
18
|
+
import edge_tts
|
|
19
|
+
|
|
20
|
+
pitch_str = pitch if isinstance(pitch, str) else f"{pitch:+.0f}Hz"
|
|
21
|
+
communicate = edge_tts.Communicate(
|
|
22
|
+
text,
|
|
23
|
+
voice,
|
|
24
|
+
pitch=pitch_str,
|
|
25
|
+
rate=f"{(speed - 1) * 100:+.0f}%",
|
|
26
|
+
)
|
|
27
|
+
chunks: list[bytes] = []
|
|
28
|
+
async for chunk in communicate.stream():
|
|
29
|
+
if chunk["type"] == "audio":
|
|
30
|
+
chunks.append(chunk["data"])
|
|
31
|
+
return b"".join(chunks)
|
|
32
|
+
|
|
33
|
+
def list_voices(self) -> list[VoiceInfo]:
|
|
34
|
+
import edge_tts
|
|
35
|
+
|
|
36
|
+
voices = []
|
|
37
|
+
# edge-tts.list_voices() is async
|
|
38
|
+
import asyncio
|
|
39
|
+
|
|
40
|
+
async def _fetch():
|
|
41
|
+
return await edge_tts.list_voices()
|
|
42
|
+
|
|
43
|
+
raw = asyncio.run(_fetch())
|
|
44
|
+
for v in raw:
|
|
45
|
+
voices.append(
|
|
46
|
+
VoiceInfo(
|
|
47
|
+
id=v["ShortName"],
|
|
48
|
+
name=v.get("FriendlyName", v["ShortName"]),
|
|
49
|
+
accent=v.get("Locale", "")[:2].upper(),
|
|
50
|
+
gender=v.get("Gender", "unknown"),
|
|
51
|
+
backend="edge-tts",
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
return voices
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""kittenTTS backend — small, local, offline TTS fallback."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from talkaty.backends.base import TTSBackend, VoiceInfo
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class KittenTTS(TTSBackend):
|
|
9
|
+
name = "kittentts"
|
|
10
|
+
|
|
11
|
+
def __init__(self) -> None:
|
|
12
|
+
try:
|
|
13
|
+
import kittentts # type: ignore
|
|
14
|
+
|
|
15
|
+
self._model = kittentts.KittenTTS()
|
|
16
|
+
except ImportError as exc: # pragma: no cover - optional dep
|
|
17
|
+
raise ImportError(
|
|
18
|
+
"kittentts is not installed. `pip install talkaty[kittentts]`"
|
|
19
|
+
) from exc
|
|
20
|
+
|
|
21
|
+
async def synthesize(
|
|
22
|
+
self,
|
|
23
|
+
text: str,
|
|
24
|
+
voice: str,
|
|
25
|
+
pitch: float | str = 0.0,
|
|
26
|
+
speed: float = 1.0,
|
|
27
|
+
) -> bytes:
|
|
28
|
+
import io
|
|
29
|
+
|
|
30
|
+
import soundfile as sf # type: ignore
|
|
31
|
+
|
|
32
|
+
audio = self._model.generate(text, voice=voice, speed=speed)
|
|
33
|
+
buf = io.BytesIO()
|
|
34
|
+
sf.write(buf, audio, 24000, format="WAV")
|
|
35
|
+
return buf.getvalue()
|
|
36
|
+
|
|
37
|
+
def list_voices(self) -> list[VoiceInfo]:
|
|
38
|
+
# kittenTTS exposes a small fixed voice set
|
|
39
|
+
return [
|
|
40
|
+
VoiceInfo(
|
|
41
|
+
id="expr-voice-2-f",
|
|
42
|
+
name="Expressive Female",
|
|
43
|
+
accent="US",
|
|
44
|
+
gender="female",
|
|
45
|
+
backend="kittentts",
|
|
46
|
+
),
|
|
47
|
+
VoiceInfo(
|
|
48
|
+
id="expr-voice-2-m",
|
|
49
|
+
name="Expressive Male",
|
|
50
|
+
accent="US",
|
|
51
|
+
gender="male",
|
|
52
|
+
backend="kittentts",
|
|
53
|
+
),
|
|
54
|
+
]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Piper TTS backend — local, offline TTS using .onnx voice models.
|
|
2
|
+
|
|
3
|
+
Each Piper model is a single voice. Provide the model path via --model.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import io
|
|
9
|
+
import wave
|
|
10
|
+
|
|
11
|
+
from talkaty.backends.base import TTSBackend, VoiceInfo
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class PiperTTS(TTSBackend):
|
|
15
|
+
name = "piper"
|
|
16
|
+
|
|
17
|
+
def __init__(self, model_path: str, config_path: str | None = None) -> None:
|
|
18
|
+
try:
|
|
19
|
+
from piper_tts import PiperVoice # type: ignore
|
|
20
|
+
except ImportError as exc: # pragma: no cover - optional dep
|
|
21
|
+
raise ImportError("piper-tts is not installed. `pip install talkaty[piper]`") from exc
|
|
22
|
+
|
|
23
|
+
self.model_path = model_path
|
|
24
|
+
self.config_path = config_path
|
|
25
|
+
self._voice = PiperVoice.load(model_path, config_path)
|
|
26
|
+
|
|
27
|
+
async def synthesize(
|
|
28
|
+
self,
|
|
29
|
+
text: str,
|
|
30
|
+
voice: str,
|
|
31
|
+
pitch: float | str = 0.0,
|
|
32
|
+
speed: float = 1.0,
|
|
33
|
+
) -> bytes:
|
|
34
|
+
"""Synthesize `text` using the loaded Piper model.
|
|
35
|
+
|
|
36
|
+
Piper does not support per-call pitch/speed adjustment; those
|
|
37
|
+
controls are silently ignored for this backend.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
buf = io.BytesIO()
|
|
41
|
+
sample_rate = int(self._voice.config.sample_rate)
|
|
42
|
+
with wave.open(buf, "wb") as wf:
|
|
43
|
+
wf.setnchannels(1)
|
|
44
|
+
wf.setsampwidth(2)
|
|
45
|
+
wf.setframerate(sample_rate)
|
|
46
|
+
for audio_bytes in self._voice.synthesize_stream_raw(text):
|
|
47
|
+
wf.writeframes(audio_bytes)
|
|
48
|
+
buf.seek(0)
|
|
49
|
+
return buf.getvalue()
|
|
50
|
+
|
|
51
|
+
def list_voices(self) -> list[VoiceInfo]:
|
|
52
|
+
return [
|
|
53
|
+
VoiceInfo(
|
|
54
|
+
id=self.model_path,
|
|
55
|
+
name=self.model_path,
|
|
56
|
+
accent="",
|
|
57
|
+
gender="unknown",
|
|
58
|
+
backend="piper",
|
|
59
|
+
)
|
|
60
|
+
]
|