1+ from __future__ import annotations
2+
3+ from typing import TYPE_CHECKING , Optional
4+
5+ import httpx
6+ from httpx import stream
7+
8+ from zai .core import (
9+ NOT_GIVEN ,
10+ BaseAPI ,
11+ Body ,
12+ Headers ,
13+ NotGiven ,
14+ make_request_options ,
15+ maybe_transform ,
16+ )
17+ from zai .types .voiceclone import (
18+ VoiceCloneParams ,
19+ VoiceCloneResult ,
20+ VoiceDeleteParams ,
21+ VoiceDeleteResult ,
22+ VoiceListParams ,
23+ VoiceListResult ,
24+ )
25+
26+ if TYPE_CHECKING :
27+ from zai ._client import ZaiClient
28+
29+
30+ class Voice (BaseAPI ):
31+ """
32+ Voice API resource for handling voice cloning operations
33+ """
34+
35+ def __init__ (self , client : ZaiClient ) -> None :
36+ super ().__init__ (client )
37+
38+ def clone (
39+ self ,
40+ * ,
41+ voice_name : str ,
42+ text : str ,
43+ input : str ,
44+ file_id : str ,
45+ request_id : Optional [str ] = None ,
46+ model : str ,
47+ extra_headers : Headers | None = None ,
48+ extra_body : Body | None = None ,
49+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
50+ ) -> VoiceCloneResult :
51+ """
52+ Clone a voice with the provided audio sample and parameters
53+
54+ Args:
55+ voice_name: Name for the cloned voice
56+ text: Text content corresponding to the sample audio
57+ input: Target text for preview audio
58+ file_id: File ID of the uploaded audio file
59+ request_id: Optional request ID for tracking
60+ model: Model
61+ extra_headers: Additional headers to include in the request
62+ extra_body: Additional body parameters
63+ timeout: Request timeout
64+
65+ Returns:
66+ Voice clone response
67+ """
68+
69+ return self ._post (
70+ "/voice/clone" ,
71+ body = maybe_transform (
72+ {
73+ "voice_name" : voice_name ,
74+ "text" : text ,
75+ "input" : input ,
76+ "file_id" : file_id ,
77+ "request_id" : request_id ,
78+ "model" : model ,
79+ },
80+ VoiceCloneParams ,
81+ ),
82+ options = make_request_options (
83+ extra_headers = extra_headers ,
84+ extra_body = extra_body ,
85+ timeout = timeout ,
86+ ),
87+ cast_type = VoiceCloneResult ,
88+ stream = False ,
89+ )
90+
91+ def delete (
92+ self ,
93+ * ,
94+ voice : str ,
95+ request_id : Optional [str ] = None ,
96+ extra_headers : Headers | None = None ,
97+ extra_body : Body | None = None ,
98+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
99+ ) -> VoiceDeleteResult :
100+ """
101+ Delete a cloned voice by voice ID
102+
103+ Args:
104+ voice: The voice to delete
105+ request_id: Optional request ID for tracking
106+ extra_headers: Additional headers to include in the request
107+ extra_body: Additional body parameters
108+ timeout: Request timeout
109+
110+ Returns:
111+ Voice deletion response
112+ """
113+ return self ._post (
114+ "/voice/delete" ,
115+ body = maybe_transform (
116+ {
117+ "voice" : voice ,
118+ "request_id" : request_id ,
119+ },
120+ VoiceDeleteParams ,
121+ ),
122+ options = make_request_options (
123+ extra_headers = extra_headers ,
124+ extra_body = extra_body ,
125+ timeout = timeout ,
126+ ),
127+ cast_type = VoiceDeleteResult ,
128+ stream = False ,
129+ )
130+
131+ def list (
132+ self ,
133+ * ,
134+ voice_type : Optional [str ] = None ,
135+ voice_name : Optional [str ] = None ,
136+ request_id : Optional [str ] = None ,
137+ extra_headers : Headers | None = None ,
138+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
139+ ) -> VoiceListResult :
140+ """
141+ List voices with optional filtering
142+
143+ Args:
144+ voice_type: Type of voice to filter by
145+ voice_name: Name of voice to filter by
146+ request_id: Optional request ID for tracking
147+ extra_headers: Additional headers to include in the request
148+ timeout: Request timeout
149+
150+ Returns:
151+ List of voices response
152+ """
153+ return self ._get (
154+ "/voice/list" ,
155+ options = make_request_options (
156+ extra_headers = {
157+ ** ({} if request_id is None else {"Request-Id" : request_id }),
158+ ** (extra_headers or {}),
159+ },
160+ extra_query = maybe_transform (
161+ {
162+ "voiceType" : voice_type ,
163+ "voiceName" : voice_name ,
164+ "request_id" : request_id ,
165+ },
166+ VoiceListParams ,
167+ ),
168+ timeout = timeout ,
169+ ),
170+ cast_type = VoiceListResult ,
171+ )
0 commit comments