finevoice 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.
- finevoice/__init__.py +3 -0
- finevoice/client.py +121 -0
- finevoice-0.1.0.dist-info/METADATA +27 -0
- finevoice-0.1.0.dist-info/RECORD +6 -0
- finevoice-0.1.0.dist-info/WHEEL +5 -0
- finevoice-0.1.0.dist-info/top_level.txt +1 -0
finevoice/__init__.py
ADDED
finevoice/client.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
from typing import Any, Dict, Optional, Union
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
DEFAULT_BASE_URL = "https://apis.finevoice.ai"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FineVoiceError(Exception):
|
|
12
|
+
def __init__(self, message: str, status: Optional[int] = None, body: Any = None):
|
|
13
|
+
super().__init__(message)
|
|
14
|
+
self.status = status
|
|
15
|
+
self.body = body
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _task_id(data: Any) -> Optional[str]:
|
|
19
|
+
if isinstance(data, dict):
|
|
20
|
+
return data.get("taskId") or data.get("task_id")
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class FineVoice:
|
|
25
|
+
"""FineVoice API client. Request bodies are plain dicts using the API field names."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, api_key: str, base_url: str = DEFAULT_BASE_URL, timeout: float = 120):
|
|
28
|
+
if not api_key:
|
|
29
|
+
raise ValueError("api_key is required")
|
|
30
|
+
self.base_url = base_url.rstrip("/")
|
|
31
|
+
self.timeout = timeout
|
|
32
|
+
self._session = requests.Session()
|
|
33
|
+
self._session.headers.update({"Authorization": f"Bearer {api_key}"})
|
|
34
|
+
|
|
35
|
+
# ---- core ----
|
|
36
|
+
def request(
|
|
37
|
+
self,
|
|
38
|
+
method: str,
|
|
39
|
+
path: str,
|
|
40
|
+
json: Optional[Dict[str, Any]] = None,
|
|
41
|
+
params: Optional[Dict[str, Any]] = None,
|
|
42
|
+
) -> Union[Dict[str, Any], bytes]:
|
|
43
|
+
params = {k: v for k, v in (params or {}).items() if v is not None}
|
|
44
|
+
resp = self._session.request(
|
|
45
|
+
method, self.base_url + path, json=json, params=params, timeout=self.timeout
|
|
46
|
+
)
|
|
47
|
+
if not resp.ok:
|
|
48
|
+
try:
|
|
49
|
+
body: Any = resp.json()
|
|
50
|
+
except ValueError:
|
|
51
|
+
body = resp.text
|
|
52
|
+
raise FineVoiceError(f"HTTP {resp.status_code} on {method} {path}", resp.status_code, body)
|
|
53
|
+
if "json" in resp.headers.get("Content-Type", ""):
|
|
54
|
+
return resp.json()
|
|
55
|
+
return resp.content
|
|
56
|
+
|
|
57
|
+
def _post(self, path: str, body: Dict[str, Any]):
|
|
58
|
+
return self.request("POST", path, json=body)
|
|
59
|
+
|
|
60
|
+
# ---- tasks ----
|
|
61
|
+
def get_task(self, task_id: str):
|
|
62
|
+
return self.request("GET", f"/v1/task/{task_id}")
|
|
63
|
+
|
|
64
|
+
def wait_for_task(self, task_or_id: Union[str, Dict[str, Any]], interval: float = 2.0, timeout: float = 600.0):
|
|
65
|
+
"""Poll until the task completes. Accepts a task id or a submit response."""
|
|
66
|
+
task_id = task_or_id if isinstance(task_or_id, str) else _task_id(task_or_id)
|
|
67
|
+
if not task_id:
|
|
68
|
+
raise FineVoiceError("No taskId in response; the result may already be available.")
|
|
69
|
+
deadline = time.monotonic() + timeout
|
|
70
|
+
while True:
|
|
71
|
+
data = self.get_task(task_id)
|
|
72
|
+
status = data.get("status") if isinstance(data, dict) else None
|
|
73
|
+
err = data.get("error") if isinstance(data, dict) else None
|
|
74
|
+
if err and (err.get("message") or err.get("code")):
|
|
75
|
+
raise FineVoiceError(f"Task {task_id} failed: {err}", body=data)
|
|
76
|
+
if status in ("failed", "error") or (isinstance(status, int) and status >= 400):
|
|
77
|
+
raise FineVoiceError(f"Task {task_id} failed", body=data)
|
|
78
|
+
if status in (200, "completed", "success"):
|
|
79
|
+
return data
|
|
80
|
+
if time.monotonic() > deadline:
|
|
81
|
+
raise FineVoiceError(f"Timed out waiting for task {task_id}", body=data)
|
|
82
|
+
time.sleep(interval)
|
|
83
|
+
|
|
84
|
+
# ---- audio ----
|
|
85
|
+
def speech_synthesis(self, body): return self._post("/v1/audio/speech-synthesis", body)
|
|
86
|
+
def voice_conversion(self, body): return self._post("/v1/audio/voice-conversion", body)
|
|
87
|
+
def speech_to_text(self, body): return self._post("/v1/audio/stt", body)
|
|
88
|
+
def sfx_generation(self, body): return self._post("/v1/audio/sfx-generation", body)
|
|
89
|
+
def audio_separation(self, body): return self._post("/v1/audio/separation", body)
|
|
90
|
+
def enhance_audio(self, body): return self._post("/v1/audio/enhanceaudio", body)
|
|
91
|
+
def reader_gen(self, body): return self._post("/v1/audio/readergen", body)
|
|
92
|
+
def podcast_gen(self, body): return self._post("/v1/audio/podcastgen", body)
|
|
93
|
+
def dubbing_gen(self, body): return self._post("/v1/audio/dubbinggen", body)
|
|
94
|
+
|
|
95
|
+
# ---- voice ----
|
|
96
|
+
def train_voice(self, body): return self._post("/v1/voice/train", body)
|
|
97
|
+
def design_voice(self, body): return self._post("/v1/voice/design", body)
|
|
98
|
+
|
|
99
|
+
def get_voice(self, name: str, desig_uuid: Optional[str] = None):
|
|
100
|
+
return self.request("GET", f"/v1/voice/{name}", params={"desigUuid": desig_uuid})
|
|
101
|
+
|
|
102
|
+
def page_voices(self, **filters):
|
|
103
|
+
"""Filters: categroy, primary_category, gender, language, keyword, page, limit, tts, style, age, sub_category."""
|
|
104
|
+
return self.request("GET", "/v1/voice/pagevoices", params=filters)
|
|
105
|
+
|
|
106
|
+
# ---- music ----
|
|
107
|
+
def music_gen_by_prompt(self, body): return self._post("/v1/music/musicgenbyprompt", body)
|
|
108
|
+
def music_gen(self, body): return self._post("/v1/music/musicgen", body)
|
|
109
|
+
def music_cover(self, body): return self._post("/v1/music/cover", body)
|
|
110
|
+
|
|
111
|
+
# ---- enhancer ----
|
|
112
|
+
def speech_enhancement(self, body): return self._post("/v1/enhancer/speech_enhancement", body)
|
|
113
|
+
def speech_super_resolution(self, body): return self._post("/v1/enhancer/speech_super_resolution", body)
|
|
114
|
+
def speech_separation(self, body): return self._post("/v1/enhancer/speech_separation", body)
|
|
115
|
+
def remove_mouth_sounds(self, body): return self._post("/v1/enhancer/remove_mouth_sounds", body)
|
|
116
|
+
def remove_long_silences(self, body): return self._post("/v1/enhancer/remove_long_silences", body)
|
|
117
|
+
def filler_words_detect(self, body): return self._post("/v1/enhancer/filler_words/detect", body)
|
|
118
|
+
def filler_words_remove(self, body): return self._post("/v1/enhancer/filler_words/remove", body)
|
|
119
|
+
def stuttering_remove(self, body): return self._post("/v1/enhancer/stuttering/remove", body)
|
|
120
|
+
def audio_normalization(self, body): return self._post("/v1/enhancer/audio_normalization", body)
|
|
121
|
+
def process_pipeline(self, body): return self._post("/v1/enhancer/process/pipeline", body)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: finevoice
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the FineVoice API
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: requests>=2.25
|
|
8
|
+
|
|
9
|
+
# FineVoice Python SDK
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install ./sdks/python
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from finevoice import FineVoice
|
|
17
|
+
|
|
18
|
+
client = FineVoice("YOUR_API_KEY")
|
|
19
|
+
|
|
20
|
+
task = client.speech_synthesis({"voice": "james", "text": "[happy] Hello from FineVoice!"})
|
|
21
|
+
result = client.wait_for_task(task) # polls GET /v1/task/{id}
|
|
22
|
+
print(result["url"])
|
|
23
|
+
|
|
24
|
+
voices = client.page_voices(language="en-US", page=0, limit=20)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Request bodies use the API field names (see the API reference). Errors raise `FineVoiceError` (`.status`, `.body`).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
finevoice/__init__.py,sha256=Mpk_wiRU7H3iD5cmUr5ygNio6Oj3XcQWo8dyGldAwVo,92
|
|
2
|
+
finevoice/client.py,sha256=4d9_MERE3iyz9gSLD7xlW3fRnlaW3fYGEoYQwTDxBa0,6033
|
|
3
|
+
finevoice-0.1.0.dist-info/METADATA,sha256=U1gH64b_5a83V3hjC-Oh4gxv6XXQ5kRXrKte-oO7CYY,721
|
|
4
|
+
finevoice-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
finevoice-0.1.0.dist-info/top_level.txt,sha256=2_v7Nj09egABftGTNsjS07X4LjVCxVSynosxLb-ITQk,10
|
|
6
|
+
finevoice-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
finevoice
|