vaakini 0.1.0__py3-none-any.whl
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.
- vaakini/__init__.py +94 -0
- vaakini/_base.py +142 -0
- vaakini/_client.py +610 -0
- vaakini/_errors.py +141 -0
- vaakini/_stream.py +407 -0
- vaakini/_types.py +278 -0
- vaakini/py.typed +0 -0
- vaakini/version.py +15 -0
- vaakini-0.1.0.dist-info/METADATA +178 -0
- vaakini-0.1.0.dist-info/RECORD +12 -0
- vaakini-0.1.0.dist-info/WHEEL +4 -0
- vaakini-0.1.0.dist-info/licenses/LICENSE +201 -0
vaakini/__init__.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Copyright 2026 Oggnai Technologies Private Limited
|
|
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
|
+
|
|
16
|
+
"""The Python SDK for Vaakini: text to speech in 12 Indian languages.
|
|
17
|
+
|
|
18
|
+
from vaakini import Vaakini
|
|
19
|
+
|
|
20
|
+
client = Vaakini() # reads VAAKINI_API_KEY
|
|
21
|
+
audio = client.speech.create(input="नमस्ते, आप कैसे हैं?", voice="Monika", language="hi")
|
|
22
|
+
|
|
23
|
+
See https://docs.vaakini.com/python.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from ._client import AsyncVaakini, Vaakini
|
|
27
|
+
from ._errors import (
|
|
28
|
+
APIConnectionError,
|
|
29
|
+
APIError,
|
|
30
|
+
APITimeoutError,
|
|
31
|
+
AuthenticationError,
|
|
32
|
+
BadRequestError,
|
|
33
|
+
CustomVoiceLimitError,
|
|
34
|
+
CustomVoicesNotEnabledError,
|
|
35
|
+
InsufficientCreditsError,
|
|
36
|
+
InternalServerError,
|
|
37
|
+
ModelTimeoutError,
|
|
38
|
+
NotFoundError,
|
|
39
|
+
RateLimitError,
|
|
40
|
+
UnavailableError,
|
|
41
|
+
VaakiniError,
|
|
42
|
+
)
|
|
43
|
+
from ._stream import AsyncSpeechStream, SpeechStream
|
|
44
|
+
from ._types import (
|
|
45
|
+
NOT_GIVEN,
|
|
46
|
+
AudioEvent,
|
|
47
|
+
CancelledEvent,
|
|
48
|
+
CustomVoice,
|
|
49
|
+
CustomVoiceList,
|
|
50
|
+
CustomVoiceModel,
|
|
51
|
+
DoneEvent,
|
|
52
|
+
Model,
|
|
53
|
+
ModelOption,
|
|
54
|
+
NotGiven,
|
|
55
|
+
SentenceEvent,
|
|
56
|
+
StreamEvent,
|
|
57
|
+
Voice,
|
|
58
|
+
)
|
|
59
|
+
from .version import __version__
|
|
60
|
+
|
|
61
|
+
__all__ = [
|
|
62
|
+
"NOT_GIVEN",
|
|
63
|
+
"APIConnectionError",
|
|
64
|
+
"APIError",
|
|
65
|
+
"APITimeoutError",
|
|
66
|
+
"AsyncSpeechStream",
|
|
67
|
+
"AsyncVaakini",
|
|
68
|
+
"AudioEvent",
|
|
69
|
+
"AuthenticationError",
|
|
70
|
+
"BadRequestError",
|
|
71
|
+
"CancelledEvent",
|
|
72
|
+
"CustomVoice",
|
|
73
|
+
"CustomVoiceLimitError",
|
|
74
|
+
"CustomVoiceList",
|
|
75
|
+
"CustomVoiceModel",
|
|
76
|
+
"CustomVoicesNotEnabledError",
|
|
77
|
+
"DoneEvent",
|
|
78
|
+
"InsufficientCreditsError",
|
|
79
|
+
"InternalServerError",
|
|
80
|
+
"Model",
|
|
81
|
+
"ModelOption",
|
|
82
|
+
"ModelTimeoutError",
|
|
83
|
+
"NotFoundError",
|
|
84
|
+
"NotGiven",
|
|
85
|
+
"RateLimitError",
|
|
86
|
+
"SentenceEvent",
|
|
87
|
+
"SpeechStream",
|
|
88
|
+
"StreamEvent",
|
|
89
|
+
"UnavailableError",
|
|
90
|
+
"Vaakini",
|
|
91
|
+
"VaakiniError",
|
|
92
|
+
"Voice",
|
|
93
|
+
"__version__",
|
|
94
|
+
]
|
vaakini/_base.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Copyright 2026 Oggnai Technologies Private Limited
|
|
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
|
+
|
|
16
|
+
"""What the sync and async clients share: the configuration and how requests are built."""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import json
|
|
21
|
+
import mimetypes
|
|
22
|
+
import os
|
|
23
|
+
from dataclasses import dataclass
|
|
24
|
+
from typing import IO, Any, Union
|
|
25
|
+
|
|
26
|
+
from .version import __version__
|
|
27
|
+
|
|
28
|
+
API_KEY_ENV = "VAAKINI_API_KEY"
|
|
29
|
+
DEFAULT_BASE_URL = "https://api.vaakini.com"
|
|
30
|
+
DEFAULT_MODEL = "vaakini-tts-1"
|
|
31
|
+
# Seconds: to connect, and between two pieces of a response.
|
|
32
|
+
DEFAULT_TIMEOUT = 60.0
|
|
33
|
+
USER_AGENT = f"vaakini-python/{__version__}"
|
|
34
|
+
|
|
35
|
+
# A reference recording: its bytes, a path to it, or an open binary file.
|
|
36
|
+
Recording = Union[bytes, str, "os.PathLike[str]", IO[bytes]]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass(frozen=True)
|
|
40
|
+
class Config:
|
|
41
|
+
api_key: str
|
|
42
|
+
base_url: str
|
|
43
|
+
timeout: float
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def read(cls, api_key: str | None, base_url: str | None, timeout: float) -> Config:
|
|
47
|
+
key = api_key or os.environ.get(API_KEY_ENV)
|
|
48
|
+
if not key:
|
|
49
|
+
raise ValueError(f"Vaakini API key is required, either as api_key or set {API_KEY_ENV}")
|
|
50
|
+
url = (base_url if base_url is not None else DEFAULT_BASE_URL).rstrip("/")
|
|
51
|
+
if not url.startswith(("https://", "http://")):
|
|
52
|
+
raise ValueError(f"base_url must start with https:// or http://; got {url!r}")
|
|
53
|
+
return cls(api_key=key, base_url=url, timeout=timeout)
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def headers(self) -> dict[str, str]:
|
|
57
|
+
return {"Authorization": f"Bearer {self.api_key}", "User-Agent": USER_AGENT}
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def stream_url(self) -> str:
|
|
61
|
+
# https:// → wss://, http:// → ws://
|
|
62
|
+
return "ws" + self.base_url.removeprefix("http") + "/v1/stream"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def options(
|
|
66
|
+
normalize: bool | None,
|
|
67
|
+
temperature: float | None,
|
|
68
|
+
top_k: int | None,
|
|
69
|
+
top_p: float | None,
|
|
70
|
+
repetition_penalty: float | None,
|
|
71
|
+
) -> dict[str, Any]:
|
|
72
|
+
"""The model's options that were given: one left out takes the model's default."""
|
|
73
|
+
given = {
|
|
74
|
+
"normalize": normalize,
|
|
75
|
+
"temperature": temperature,
|
|
76
|
+
"top_k": top_k,
|
|
77
|
+
"top_p": top_p,
|
|
78
|
+
"repetition_penalty": repetition_penalty,
|
|
79
|
+
}
|
|
80
|
+
return {name: value for name, value in given.items() if value is not None}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def speech_body(
|
|
84
|
+
*,
|
|
85
|
+
input: str,
|
|
86
|
+
voice: str,
|
|
87
|
+
language: str | None,
|
|
88
|
+
response_format: str,
|
|
89
|
+
model: str,
|
|
90
|
+
options: dict[str, Any],
|
|
91
|
+
) -> dict[str, Any]:
|
|
92
|
+
body: dict[str, Any] = {
|
|
93
|
+
"model": model,
|
|
94
|
+
"input": input,
|
|
95
|
+
"voice": voice,
|
|
96
|
+
"response_format": response_format,
|
|
97
|
+
**options,
|
|
98
|
+
}
|
|
99
|
+
if language is not None:
|
|
100
|
+
body["language"] = language
|
|
101
|
+
return body
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def stream_fields(
|
|
105
|
+
*, voice: str, language: str | None, format: str, model: str, options: dict[str, Any]
|
|
106
|
+
) -> dict[str, Any]:
|
|
107
|
+
"""What `start` and `warm` share."""
|
|
108
|
+
fields: dict[str, Any] = {
|
|
109
|
+
"model": model,
|
|
110
|
+
"voice": voice,
|
|
111
|
+
"format": format,
|
|
112
|
+
"sample_rate": 24000,
|
|
113
|
+
"options": options,
|
|
114
|
+
}
|
|
115
|
+
if language is not None:
|
|
116
|
+
fields["language"] = language
|
|
117
|
+
return fields
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def recording_form(
|
|
121
|
+
*,
|
|
122
|
+
audio: Recording,
|
|
123
|
+
transcript: str,
|
|
124
|
+
language: str,
|
|
125
|
+
mode: str | None,
|
|
126
|
+
model: str,
|
|
127
|
+
) -> tuple[dict[str, str], dict[str, tuple[str, bytes, str]]]:
|
|
128
|
+
"""A recording's multipart form: its text fields, and the `audio` file part."""
|
|
129
|
+
data = {"transcript": transcript, "language": language}
|
|
130
|
+
if mode is not None:
|
|
131
|
+
data["models"] = json.dumps({model: {"mode": mode}})
|
|
132
|
+
if isinstance(audio, bytes):
|
|
133
|
+
name, content = "recording", audio
|
|
134
|
+
elif isinstance(audio, (str, os.PathLike)):
|
|
135
|
+
name = os.path.basename(os.fspath(audio))
|
|
136
|
+
with open(audio, "rb") as f:
|
|
137
|
+
content = f.read()
|
|
138
|
+
else:
|
|
139
|
+
content = audio.read()
|
|
140
|
+
name = os.path.basename(str(getattr(audio, "name", "recording")))
|
|
141
|
+
content_type = mimetypes.guess_type(name)[0] or "application/octet-stream"
|
|
142
|
+
return data, {"audio": (name, content, content_type)}
|