livekit-plugins-speechify 1.3.9__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.
- livekit_plugins_speechify-1.3.9/.gitignore +179 -0
- livekit_plugins_speechify-1.3.9/PKG-INFO +38 -0
- livekit_plugins_speechify-1.3.9/README.md +15 -0
- livekit_plugins_speechify-1.3.9/livekit/plugins/speechify/__init__.py +52 -0
- livekit_plugins_speechify-1.3.9/livekit/plugins/speechify/log.py +17 -0
- livekit_plugins_speechify-1.3.9/livekit/plugins/speechify/models.py +29 -0
- livekit_plugins_speechify-1.3.9/livekit/plugins/speechify/py.typed +0 -0
- livekit_plugins_speechify-1.3.9/livekit/plugins/speechify/tts.py +293 -0
- livekit_plugins_speechify-1.3.9/livekit/plugins/speechify/version.py +15 -0
- livekit_plugins_speechify-1.3.9/pyproject.toml +39 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
**/.vscode
|
|
2
|
+
**/.DS_Store
|
|
3
|
+
|
|
4
|
+
# Byte-compiled / optimized / DLL files
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
|
|
9
|
+
# C extensions
|
|
10
|
+
*.so
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
.Python
|
|
14
|
+
build/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
dist/
|
|
17
|
+
downloads/
|
|
18
|
+
eggs/
|
|
19
|
+
.eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
wheels/
|
|
26
|
+
share/python-wheels/
|
|
27
|
+
*.egg-info/
|
|
28
|
+
.installed.cfg
|
|
29
|
+
*.egg
|
|
30
|
+
MANIFEST
|
|
31
|
+
|
|
32
|
+
# PyInstaller
|
|
33
|
+
# Usually these files are written by a python script from a template
|
|
34
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
35
|
+
*.manifest
|
|
36
|
+
*.spec
|
|
37
|
+
|
|
38
|
+
# Installer logs
|
|
39
|
+
pip-log.txt
|
|
40
|
+
pip-delete-this-directory.txt
|
|
41
|
+
|
|
42
|
+
# Unit test / coverage reports
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cache
|
|
49
|
+
nosetests.xml
|
|
50
|
+
coverage.xml
|
|
51
|
+
*.cover
|
|
52
|
+
*.py,cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
.pytest_cache/
|
|
55
|
+
cover/
|
|
56
|
+
|
|
57
|
+
# Translations
|
|
58
|
+
*.mo
|
|
59
|
+
*.pot
|
|
60
|
+
|
|
61
|
+
# Django stuff:
|
|
62
|
+
*.log
|
|
63
|
+
local_settings.py
|
|
64
|
+
db.sqlite3
|
|
65
|
+
db.sqlite3-journal
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
.pybuilder/
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
|
|
84
|
+
# IPython
|
|
85
|
+
profile_default/
|
|
86
|
+
ipython_config.py
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
90
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
91
|
+
# .python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# poetry
|
|
101
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
102
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
103
|
+
# commonly ignored for libraries.
|
|
104
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
105
|
+
#poetry.lock
|
|
106
|
+
|
|
107
|
+
# pdm
|
|
108
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
109
|
+
#pdm.lock
|
|
110
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
111
|
+
# in version control.
|
|
112
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
113
|
+
.pdm.toml
|
|
114
|
+
|
|
115
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
116
|
+
__pypackages__/
|
|
117
|
+
|
|
118
|
+
# Celery stuff
|
|
119
|
+
celerybeat-schedule
|
|
120
|
+
celerybeat.pid
|
|
121
|
+
|
|
122
|
+
# SageMath parsed files
|
|
123
|
+
*.sage.py
|
|
124
|
+
|
|
125
|
+
# Environments
|
|
126
|
+
.env
|
|
127
|
+
.venv
|
|
128
|
+
env/
|
|
129
|
+
venv/
|
|
130
|
+
ENV/
|
|
131
|
+
env.bak/
|
|
132
|
+
venv.bak/
|
|
133
|
+
|
|
134
|
+
# Spyder project settings
|
|
135
|
+
.spyderproject
|
|
136
|
+
.spyproject
|
|
137
|
+
|
|
138
|
+
# Rope project settings
|
|
139
|
+
.ropeproject
|
|
140
|
+
|
|
141
|
+
# mkdocs documentation
|
|
142
|
+
/site
|
|
143
|
+
|
|
144
|
+
# mypy
|
|
145
|
+
.mypy_cache/
|
|
146
|
+
.dmypy.json
|
|
147
|
+
dmypy.json
|
|
148
|
+
|
|
149
|
+
# trunk
|
|
150
|
+
.trunk/
|
|
151
|
+
|
|
152
|
+
# Pyre type checker
|
|
153
|
+
.pyre/
|
|
154
|
+
|
|
155
|
+
# pytype static type analyzer
|
|
156
|
+
.pytype/
|
|
157
|
+
|
|
158
|
+
# Cython debug symbols
|
|
159
|
+
cython_debug/
|
|
160
|
+
|
|
161
|
+
# PyCharm
|
|
162
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
163
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
164
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
165
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
166
|
+
.idea/
|
|
167
|
+
|
|
168
|
+
node_modules
|
|
169
|
+
|
|
170
|
+
credentials.json
|
|
171
|
+
pyrightconfig.json
|
|
172
|
+
docs/
|
|
173
|
+
|
|
174
|
+
# Database files
|
|
175
|
+
*.db
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
# Examples for development
|
|
179
|
+
examples/dev/*
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: livekit-plugins-speechify
|
|
3
|
+
Version: 1.3.9
|
|
4
|
+
Summary: Agent Framework plugin for voice synthesis with Speechify's API.
|
|
5
|
+
Project-URL: Documentation, https://docs.livekit.io
|
|
6
|
+
Project-URL: Website, https://livekit.io/
|
|
7
|
+
Project-URL: Source, https://github.com/livekit/agents
|
|
8
|
+
Author-email: LiveKit <hello@livekit.io>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
Keywords: audio,livekit,realtime,speechify,video,webrtc
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
18
|
+
Classifier: Topic :: Multimedia :: Video
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.9.0
|
|
21
|
+
Requires-Dist: livekit-agents[codecs]>=1.3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# Speechify TTS plugin for LiveKit Agents
|
|
25
|
+
|
|
26
|
+
Support for voice synthesis with the [Speechify](https://www.speechify.ai/) API.
|
|
27
|
+
|
|
28
|
+
See [https://docs.livekit.io/agents/integrations/tts/speechify/](https://docs.livekit.io/agents/integrations/tts/speechify/) for more information.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install livekit-plugins-speechify
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Pre-requisites
|
|
37
|
+
|
|
38
|
+
You'll need an API key from Speechify. It can be set as an environment variable: `SPEECHIFY_API_KEY`
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Speechify TTS plugin for LiveKit Agents
|
|
2
|
+
|
|
3
|
+
Support for voice synthesis with the [Speechify](https://www.speechify.ai/) API.
|
|
4
|
+
|
|
5
|
+
See [https://docs.livekit.io/agents/integrations/tts/speechify/](https://docs.livekit.io/agents/integrations/tts/speechify/) for more information.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install livekit-plugins-speechify
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Pre-requisites
|
|
14
|
+
|
|
15
|
+
You'll need an API key from Speechify. It can be set as an environment variable: `SPEECHIFY_API_KEY`
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright 2023 LiveKit, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Speechify plugin for LiveKit Agents
|
|
16
|
+
|
|
17
|
+
See https://docs.livekit.io/agents/integrations/tts/speechify/ for more information.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from .models import TTSEncoding, TTSModels
|
|
21
|
+
from .tts import DEFAULT_VOICE_ID, TTS, Voice
|
|
22
|
+
from .version import __version__
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"TTS",
|
|
26
|
+
"Voice",
|
|
27
|
+
"TTSEncoding",
|
|
28
|
+
"TTSModels",
|
|
29
|
+
"DEFAULT_VOICE_ID",
|
|
30
|
+
"__version__",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
from livekit.agents import Plugin
|
|
34
|
+
|
|
35
|
+
from .log import logger
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class SpeechifyPlugin(Plugin):
|
|
39
|
+
def __init__(self) -> None:
|
|
40
|
+
super().__init__(__name__, __version__, __package__, logger)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Plugin.register_plugin(SpeechifyPlugin())
|
|
44
|
+
|
|
45
|
+
# Cleanup docs of unexported modules
|
|
46
|
+
_module = dir()
|
|
47
|
+
NOT_IN_ALL = [m for m in _module if m not in __all__]
|
|
48
|
+
|
|
49
|
+
__pdoc__ = {}
|
|
50
|
+
|
|
51
|
+
for n in NOT_IN_ALL:
|
|
52
|
+
__pdoc__[n] = False
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright 2024 LiveKit, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import logging
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger("livekit.plugins.speechify")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright 2024 LiveKit, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
from typing import Literal
|
|
15
|
+
|
|
16
|
+
TTSModels = Literal[
|
|
17
|
+
"simba-english",
|
|
18
|
+
"simba-multilingual",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
TTSEncoding = Literal[
|
|
22
|
+
"mp3_24000",
|
|
23
|
+
"wav_48000",
|
|
24
|
+
"ogg_24000",
|
|
25
|
+
"aac_24000",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
VoiceType = Literal["shared", "personal"]
|
|
29
|
+
Gender = Literal["male", "female", "neutral"]
|
|
File without changes
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# Copyright 2023 LiveKit, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import asyncio
|
|
18
|
+
import os
|
|
19
|
+
from dataclasses import dataclass, replace
|
|
20
|
+
from typing import cast
|
|
21
|
+
|
|
22
|
+
import aiohttp
|
|
23
|
+
|
|
24
|
+
from livekit.agents import (
|
|
25
|
+
APIConnectionError,
|
|
26
|
+
APIConnectOptions,
|
|
27
|
+
APIError,
|
|
28
|
+
APIStatusError,
|
|
29
|
+
APITimeoutError,
|
|
30
|
+
tts,
|
|
31
|
+
utils,
|
|
32
|
+
)
|
|
33
|
+
from livekit.agents.types import (
|
|
34
|
+
DEFAULT_API_CONNECT_OPTIONS,
|
|
35
|
+
NOT_GIVEN,
|
|
36
|
+
NotGivenOr,
|
|
37
|
+
)
|
|
38
|
+
from livekit.agents.utils import is_given
|
|
39
|
+
|
|
40
|
+
from .models import Gender, TTSEncoding, TTSModels, VoiceType
|
|
41
|
+
|
|
42
|
+
_DefaultEncoding: TTSEncoding = "ogg_24000"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _sample_rate_from_encoding(output_encoding: TTSEncoding) -> int:
|
|
46
|
+
split = output_encoding.split("_")
|
|
47
|
+
return int(split[1])
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _audio_format_from_encoding(encoding: TTSEncoding) -> str:
|
|
51
|
+
split = encoding.split("_")
|
|
52
|
+
return split[0]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
DEFAULT_VOICE_ID = "jack"
|
|
56
|
+
API_BASE_URL_V1 = "https://api.sws.speechify.com/v1"
|
|
57
|
+
AUTHORIZATION_HEADER = "Authorization"
|
|
58
|
+
CALLER_HEADER = "x-caller"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass
|
|
62
|
+
class Voice:
|
|
63
|
+
id: str
|
|
64
|
+
type: VoiceType
|
|
65
|
+
display_name: str
|
|
66
|
+
gender: Gender
|
|
67
|
+
avatar_image: str | None
|
|
68
|
+
models: list[TTSModels]
|
|
69
|
+
locale: str
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass
|
|
73
|
+
class _TTSOptions:
|
|
74
|
+
base_url: NotGivenOr[str]
|
|
75
|
+
token: str
|
|
76
|
+
voice_id: str
|
|
77
|
+
encoding: TTSEncoding
|
|
78
|
+
language: NotGivenOr[str]
|
|
79
|
+
model: NotGivenOr[TTSModels]
|
|
80
|
+
loudness_normalization: NotGivenOr[bool]
|
|
81
|
+
text_normalization: NotGivenOr[bool]
|
|
82
|
+
follow_redirects: bool
|
|
83
|
+
sample_rate: int
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class TTS(tts.TTS):
|
|
87
|
+
def __init__(
|
|
88
|
+
self,
|
|
89
|
+
*,
|
|
90
|
+
voice_id: NotGivenOr[str] = DEFAULT_VOICE_ID,
|
|
91
|
+
encoding: NotGivenOr[TTSEncoding] = NOT_GIVEN,
|
|
92
|
+
model: NotGivenOr[TTSModels] = NOT_GIVEN,
|
|
93
|
+
base_url: NotGivenOr[str] = NOT_GIVEN,
|
|
94
|
+
api_key: NotGivenOr[str] = NOT_GIVEN,
|
|
95
|
+
language: NotGivenOr[str] = NOT_GIVEN,
|
|
96
|
+
loudness_normalization: NotGivenOr[bool] = NOT_GIVEN,
|
|
97
|
+
text_normalization: NotGivenOr[bool] = NOT_GIVEN,
|
|
98
|
+
http_session: aiohttp.ClientSession | None = None,
|
|
99
|
+
follow_redirects: bool = True,
|
|
100
|
+
) -> None:
|
|
101
|
+
"""
|
|
102
|
+
Create a new instance of Speechify TTS.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
voice_id (NotGivenOr[str]): Voice ID. Defaults to `cliff`.
|
|
106
|
+
encoding (NotGivenOr[TTSEncoding]): Audio encoding to use. Optional. Defaults to `wav_48000`.
|
|
107
|
+
model (NotGivenOr[TTSModels]): TTS model to use. Optional.
|
|
108
|
+
base_url (NotGivenOr[str]): Custom base URL for the API. Optional.
|
|
109
|
+
api_key (NotGivenOr[str]): Speechify API key. Can be set via argument or `SPEECHIFY_API_KEY` environment variable
|
|
110
|
+
language (NotGivenOr[str]): Language code for the TTS model. Optional.
|
|
111
|
+
loudness_normalization (NotGivenOr[bool]): Whether to normalize the loudness of the audio. Optional.
|
|
112
|
+
text_normalization (NotGivenOr[bool]): Whether to normalize the text. Optional.
|
|
113
|
+
http_session (aiohttp.ClientSession | None): Custom HTTP session for API requests. Optional.
|
|
114
|
+
follow_redirects (bool): Whether to follow redirects in HTTP requests. Defaults to True.
|
|
115
|
+
""" # noqa: E501
|
|
116
|
+
|
|
117
|
+
if not is_given(encoding):
|
|
118
|
+
encoding = _DefaultEncoding
|
|
119
|
+
|
|
120
|
+
super().__init__(
|
|
121
|
+
capabilities=tts.TTSCapabilities(
|
|
122
|
+
streaming=False,
|
|
123
|
+
),
|
|
124
|
+
sample_rate=_sample_rate_from_encoding(encoding),
|
|
125
|
+
num_channels=1,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
speechify_token = api_key if is_given(api_key) else os.environ.get("SPEECHIFY_API_KEY")
|
|
129
|
+
if not (speechify_token):
|
|
130
|
+
raise ValueError(
|
|
131
|
+
"Speechify API key is required, either as argument or set SPEECHIFY_API_KEY environment variable" # noqa: E501
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
self._opts = _TTSOptions(
|
|
135
|
+
model=model,
|
|
136
|
+
voice_id=voice_id or DEFAULT_VOICE_ID,
|
|
137
|
+
language=language,
|
|
138
|
+
base_url=base_url if is_given(base_url) else API_BASE_URL_V1,
|
|
139
|
+
token=speechify_token,
|
|
140
|
+
follow_redirects=follow_redirects,
|
|
141
|
+
encoding=encoding,
|
|
142
|
+
sample_rate=_sample_rate_from_encoding(encoding),
|
|
143
|
+
loudness_normalization=loudness_normalization,
|
|
144
|
+
text_normalization=text_normalization,
|
|
145
|
+
)
|
|
146
|
+
self._session = http_session
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def model(self) -> str:
|
|
150
|
+
return self._opts.model if is_given(self._opts.model) else "unknown"
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def provider(self) -> str:
|
|
154
|
+
return "Speechify"
|
|
155
|
+
|
|
156
|
+
def _ensure_session(self) -> aiohttp.ClientSession:
|
|
157
|
+
if not self._session:
|
|
158
|
+
self._session = utils.http_context.http_session()
|
|
159
|
+
|
|
160
|
+
return self._session
|
|
161
|
+
|
|
162
|
+
async def list_voices(self) -> list[Voice]:
|
|
163
|
+
async with self._ensure_session().get(
|
|
164
|
+
f"{self._opts.base_url}/voices", headers=_get_headers(self._opts.token)
|
|
165
|
+
) as resp:
|
|
166
|
+
return await resp.json() # type: ignore
|
|
167
|
+
|
|
168
|
+
def update_options(
|
|
169
|
+
self,
|
|
170
|
+
*,
|
|
171
|
+
voice_id: NotGivenOr[str] = NOT_GIVEN,
|
|
172
|
+
model: NotGivenOr[TTSModels] = NOT_GIVEN,
|
|
173
|
+
language: NotGivenOr[str] = NOT_GIVEN,
|
|
174
|
+
loudness_normalization: NotGivenOr[bool] = NOT_GIVEN,
|
|
175
|
+
text_normalization: NotGivenOr[bool] = NOT_GIVEN,
|
|
176
|
+
) -> None:
|
|
177
|
+
"""
|
|
178
|
+
Args:
|
|
179
|
+
voice_id (NotGivenOr[str]): Voice ID.
|
|
180
|
+
model (NotGivenOr[TTSModels | str]): TTS model to use.
|
|
181
|
+
language (NotGivenOr[str]): Language code for the TTS model.
|
|
182
|
+
"""
|
|
183
|
+
if is_given(model):
|
|
184
|
+
self._opts.model = cast(TTSModels, model)
|
|
185
|
+
if is_given(voice_id):
|
|
186
|
+
self._opts.voice_id = voice_id
|
|
187
|
+
if is_given(language):
|
|
188
|
+
self._opts.language = language
|
|
189
|
+
if is_given(loudness_normalization):
|
|
190
|
+
self._opts.loudness_normalization = loudness_normalization
|
|
191
|
+
if is_given(text_normalization):
|
|
192
|
+
self._opts.text_normalization = text_normalization
|
|
193
|
+
|
|
194
|
+
def synthesize(
|
|
195
|
+
self,
|
|
196
|
+
text: str,
|
|
197
|
+
*,
|
|
198
|
+
conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
|
|
199
|
+
) -> ChunkedStream:
|
|
200
|
+
return ChunkedStream(tts=self, input_text=text, conn_options=conn_options)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
class ChunkedStream(tts.ChunkedStream):
|
|
204
|
+
"""Synthesize using the chunked api endpoint"""
|
|
205
|
+
|
|
206
|
+
def __init__(self, *, tts: TTS, input_text: str, conn_options: APIConnectOptions) -> None:
|
|
207
|
+
super().__init__(tts=tts, input_text=input_text, conn_options=conn_options)
|
|
208
|
+
self._tts: TTS = tts
|
|
209
|
+
self._opts = replace(tts._opts)
|
|
210
|
+
|
|
211
|
+
async def _run(self, output_emitter: tts.AudioEmitter) -> None:
|
|
212
|
+
data = {
|
|
213
|
+
"input": self._input_text,
|
|
214
|
+
"voice_id": self._opts.voice_id,
|
|
215
|
+
"language": self._opts.language if is_given(self._opts.language) else None,
|
|
216
|
+
"model": self._opts.model if is_given(self._opts.model) else None,
|
|
217
|
+
"audio_format": _audio_format_from_encoding(self._opts.encoding),
|
|
218
|
+
"options": {
|
|
219
|
+
"loudness_normalization": self._opts.loudness_normalization
|
|
220
|
+
if is_given(self._opts.loudness_normalization)
|
|
221
|
+
else None,
|
|
222
|
+
"text_normalization": self._opts.text_normalization
|
|
223
|
+
if is_given(self._opts.text_normalization)
|
|
224
|
+
else None,
|
|
225
|
+
},
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
try:
|
|
229
|
+
async with self._tts._ensure_session().post(
|
|
230
|
+
_synthesize_url(self._opts),
|
|
231
|
+
headers=_get_headers(self._opts.token, encoding=self._opts.encoding),
|
|
232
|
+
json=data,
|
|
233
|
+
timeout=aiohttp.ClientTimeout(connect=self._conn_options.timeout, total=30),
|
|
234
|
+
) as resp:
|
|
235
|
+
resp.raise_for_status()
|
|
236
|
+
|
|
237
|
+
if not resp.content_type.startswith("audio/"):
|
|
238
|
+
content = await resp.text()
|
|
239
|
+
raise APIError(message="Speechify returned non-audio data", body=content)
|
|
240
|
+
|
|
241
|
+
output_emitter.initialize(
|
|
242
|
+
request_id=utils.shortuuid(),
|
|
243
|
+
sample_rate=self._opts.sample_rate,
|
|
244
|
+
num_channels=1,
|
|
245
|
+
mime_type=f"audio/{_audio_format_from_encoding(self._opts.encoding)}",
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
async for chunk, _ in resp.content.iter_chunks():
|
|
249
|
+
output_emitter.push(chunk)
|
|
250
|
+
|
|
251
|
+
output_emitter.flush()
|
|
252
|
+
|
|
253
|
+
except asyncio.TimeoutError:
|
|
254
|
+
raise APITimeoutError() from None
|
|
255
|
+
except aiohttp.ClientResponseError as e:
|
|
256
|
+
raise APIStatusError(
|
|
257
|
+
message=e.message,
|
|
258
|
+
status_code=e.status,
|
|
259
|
+
request_id=None,
|
|
260
|
+
body=None,
|
|
261
|
+
) from None
|
|
262
|
+
except Exception as e:
|
|
263
|
+
raise APIConnectionError() from e
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _synthesize_url(opts: _TTSOptions) -> str:
|
|
267
|
+
"""Construct the Speechify stream URL."""
|
|
268
|
+
return f"{opts.base_url}/audio/stream"
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _get_headers(token: str, *, encoding: TTSEncoding | None = None) -> dict[str, str]:
|
|
272
|
+
"""Construct the headers for the Speechify API."""
|
|
273
|
+
headers = {
|
|
274
|
+
AUTHORIZATION_HEADER: f"Bearer {token}" if not token.startswith("Bearer ") else token
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if encoding:
|
|
278
|
+
accept = ""
|
|
279
|
+
format = _audio_format_from_encoding(encoding)
|
|
280
|
+
if format == "ogg":
|
|
281
|
+
accept = "audio/ogg"
|
|
282
|
+
elif format == "mp3":
|
|
283
|
+
accept = "audio/mpeg"
|
|
284
|
+
elif format == "aac":
|
|
285
|
+
accept = "audio/aac"
|
|
286
|
+
|
|
287
|
+
# docs does not specify mime type for wav
|
|
288
|
+
# https://docs.sws.speechify.com/v1/api-reference/api-reference/tts/audio/stream
|
|
289
|
+
|
|
290
|
+
if accept:
|
|
291
|
+
headers["Accept"] = accept
|
|
292
|
+
headers[CALLER_HEADER] = "livekit"
|
|
293
|
+
return headers
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copyright 2024 LiveKit, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
__version__ = "1.3.9"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "livekit-plugins-speechify"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Agent Framework plugin for voice synthesis with Speechify's API."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
requires-python = ">=3.9.0"
|
|
12
|
+
authors = [{ name = "LiveKit", email = "hello@livekit.io" }]
|
|
13
|
+
keywords = ["webrtc", "realtime", "audio", "video", "livekit", "speechify"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: Apache Software License",
|
|
17
|
+
"Topic :: Multimedia :: Sound/Audio",
|
|
18
|
+
"Topic :: Multimedia :: Video",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
24
|
+
]
|
|
25
|
+
dependencies = ["livekit-agents[codecs]>=1.3.9"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Documentation = "https://docs.livekit.io"
|
|
29
|
+
Website = "https://livekit.io/"
|
|
30
|
+
Source = "https://github.com/livekit/agents"
|
|
31
|
+
|
|
32
|
+
[tool.hatch.version]
|
|
33
|
+
path = "livekit/plugins/speechify/version.py"
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.wheel]
|
|
36
|
+
packages = ["livekit"]
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.sdist]
|
|
39
|
+
include = ["/livekit"]
|