@@ -16,6 +16,17 @@ class TextToSpeechParams(TypedDict):
1616 speaker_clone_file_store_key : NotRequired [str ]
1717
1818
19+ class TTSCloneParams (TypedDict ):
20+ url : NotRequired [str ]
21+ file_store_key : NotRequired [str ]
22+ name : str
23+
24+
25+ class GetTTSVoiceClonesParams (TypedDict ):
26+ limit : NotRequired [int ]
27+ page : NotRequired [int ]
28+
29+
1930class TextToSpeechResponse (TypedDict ):
2031 success : bool
2132 text : str
@@ -70,12 +81,10 @@ def speech_to_text(self, params: SpeechToTextParams) -> SpeechToTextResponse: ..
7081 @overload
7182 def speech_to_text (self , file : bytes , options : Optional [SpeechToTextParams ] = None ) -> SpeechToTextResponse : ...
7283
73- def speech_to_text (
74- self ,
75- blob : Union [SpeechToTextParams , bytes ],
76- options : Optional [SpeechToTextParams ] = None ,
77- ) -> SpeechToTextResponse :
78- if isinstance (blob , dict ): # If params is provided as a dict, we assume it's the first argument
84+ def speech_to_text (self , blob : Union [SpeechToTextParams , bytes ], options : Optional [SpeechToTextParams ] = None ) -> SpeechToTextResponse :
85+ if isinstance (
86+ blob , dict
87+ ): # If params is provided as a dict, we assume it's the first argument
7988 resp = Request (
8089 config = self .config ,
8190 path = "/ai/transcribe" ,
@@ -89,17 +98,9 @@ def speech_to_text(
8998 content_type = options .get ("content_type" , "application/octet-stream" )
9099 headers = {"Content-Type" : content_type }
91100
92- resp = Request (
93- config = self .config ,
94- path = path ,
95- params = options ,
96- data = blob ,
97- headers = headers ,
98- verb = "post" ,
99- ).perform_with_content ()
101+ resp = Request (config = self .config , path = path , params = options , data = blob , headers = headers , verb = "post" ).perform_with_content ()
100102 return resp
101103
102-
103104 def text_to_speech (self , params : TextToSpeechParams ) -> TextToSpeechResponse :
104105 path = "/ai/tts"
105106 resp = Request (
@@ -112,12 +113,23 @@ def text_to_speech(self, params: TextToSpeechParams) -> TextToSpeechResponse:
112113
113114 def speaker_voice_accents (self ) -> TextToSpeechResponse :
114115 path = "/ai/tts"
115- resp = Request (
116- config = self .config ,
117- path = path ,
118- params = {},
119- verb = "get" ,
120- ).perform_with_content ()
116+ resp = Request (config = self .config , path = path , params = {}, verb = "get" ).perform_with_content ()
117+ return resp
118+
119+ def create_clone (self , params : TTSCloneParams ) -> TextToSpeechResponse :
120+ path = "/ai/tts/clone"
121+ resp = Request (config = self .config , path = path , params = cast (Dict [Any , Any ], params ), verb = "post" ).perform_with_content ()
122+
123+ return resp
124+
125+ def get_clones (self , params : GetTTSVoiceClonesParams ) -> TextToSpeechResponse :
126+ path = "/ai/tts/clone"
127+ resp = Request (config = self .config , path = path , params = cast (Dict [Any , Any ], params ), verb = "get" ).perform_with_content ()
128+ return resp
129+
130+ def delete_clone (self , voice_id : str ) -> TextToSpeechResponse :
131+ path = f"/ai/tts/clone/{ voice_id } "
132+ resp = Request (config = self .config , path = path , params = {}, verb = "delete" ).perform_with_content ()
121133 return resp
122134
123135
@@ -140,7 +152,9 @@ def __init__(
140152 @overload
141153 async def speech_to_text (self , params : SpeechToTextParams ) -> SpeechToTextResponse : ...
142154 @overload
143- async def speech_to_text (self , file : bytes , options : Optional [SpeechToTextParams ] = None ) -> SpeechToTextResponse : ...
155+ async def speech_to_text (
156+ self , file : bytes , options : Optional [SpeechToTextParams ] = None
157+ ) -> SpeechToTextResponse : ...
144158
145159 async def speech_to_text (
146160 self ,
@@ -155,7 +169,7 @@ async def speech_to_text(
155169 verb = "post" ,
156170 ).perform_with_content ()
157171 return resp
158-
172+
159173 options = options or {}
160174 path = build_path (base_path = "/ai/transcribe" , params = options )
161175 content_type = options .get ("content_type" , "application/octet-stream" )
@@ -190,3 +204,33 @@ async def speaker_voice_accents(self) -> TextToSpeechResponse:
190204 verb = "get" ,
191205 ).perform_with_content ()
192206 return resp
207+
208+ async def create_clone (self , params : TTSCloneParams ) -> TextToSpeechResponse :
209+ path = "/ai/tts/clone"
210+ resp = await AsyncRequest (
211+ config = self .config ,
212+ path = path ,
213+ params = cast (Dict [Any , Any ], params ),
214+ verb = "post"
215+ ).perform_with_content ()
216+ return resp
217+
218+ async def get_clones (self , params : GetTTSVoiceClonesParams ) -> TextToSpeechResponse :
219+ path = "/ai/tts/clone"
220+ resp = await AsyncRequest (
221+ config = self .config ,
222+ path = path ,
223+ params = cast (Dict [Any , Any ], params ),
224+ verb = "get"
225+ ).perform_with_content ()
226+ return resp
227+
228+ async def delete_clone (self , voice_id : str ) -> TextToSpeechResponse :
229+ path = f"/ai/tts/clone/{ voice_id } "
230+ resp = await AsyncRequest (
231+ config = self .config ,
232+ path = path ,
233+ params = {},
234+ verb = "delete"
235+ ).perform_with_content ()
236+ return resp
0 commit comments