11from __future__ import annotations
22
3- from ... core import BaseAPI , cached_property
3+ from typing import TYPE_CHECKING , List , Mapping , cast , Optional , Dict
44from .transcriptions import Transcriptions
55
6+ from zhipuai .core ._utils import extract_files
7+
8+ from zhipuai .types .sensitive_word_check import SensitiveWordCheckRequest
9+ from zhipuai .types .audio import AudioSpeechParams
10+ from ...types .audio import audio_customization_param
611
12+ from zhipuai .core import BaseAPI , maybe_transform
13+ from zhipuai .core import NOT_GIVEN , Body , Headers , NotGiven , FileTypes
14+ from zhipuai .core import _legacy_response
15+
16+ import httpx
17+ from ...core import BaseAPI , cached_property
18+
19+ from zhipuai .core import (
20+ make_request_options ,
21+ )
22+ from zhipuai .core import deepcopy_minimal
23+
24+ if TYPE_CHECKING :
25+ from zhipuai ._client import ZhipuAI
726
827__all__ = ["Audio" ]
28+
29+
930class Audio (BaseAPI ):
31+
1032 @cached_property
1133 def transcriptions (self ) -> Transcriptions :
1234 return Transcriptions (self ._client )
35+
36+ def __init__ (self , client : "ZhipuAI" ) -> None :
37+ super ().__init__ (client )
38+
39+ def speech (
40+ self ,
41+ * ,
42+ model : str ,
43+ input : str = None ,
44+ voice : str = None ,
45+ response_format : str = None ,
46+ sensitive_word_check : Optional [SensitiveWordCheckRequest ] | NotGiven = NOT_GIVEN ,
47+ request_id : str = None ,
48+ user_id : str = None ,
49+ extra_headers : Headers | None = None ,
50+ extra_body : Body | None = None ,
51+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
52+ ) -> _legacy_response .HttpxBinaryResponseContent :
53+ body = deepcopy_minimal (
54+ {
55+ "model" : model ,
56+ "input" : input ,
57+ "voice" : voice ,
58+ "response_format" : response_format ,
59+ "sensitive_word_check" : sensitive_word_check ,
60+ "request_id" : request_id ,
61+ "user_id" : user_id
62+ }
63+ )
64+ return self ._post (
65+ "/audio/speech" ,
66+ body = maybe_transform (body , AudioSpeechParams ),
67+ options = make_request_options (
68+ extra_headers = extra_headers , extra_body = extra_body , timeout = timeout
69+ ),
70+ cast_type = _legacy_response .HttpxBinaryResponseContent
71+ )
72+
73+ def customization (
74+ self ,
75+ * ,
76+ model : str ,
77+ input : str = None ,
78+ voice_text : str = None ,
79+ voice_data : FileTypes = None ,
80+ response_format : str = None ,
81+ sensitive_word_check : Optional [SensitiveWordCheckRequest ] | NotGiven = NOT_GIVEN ,
82+ request_id : str = None ,
83+ user_id : str = None ,
84+ extra_headers : Headers | None = None ,
85+ extra_body : Body | None = None ,
86+ timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
87+ ) -> _legacy_response .HttpxBinaryResponseContent :
88+ body = deepcopy_minimal (
89+ {
90+ "model" : model ,
91+ "input" : input ,
92+ "voice_text" : voice_text ,
93+ "voice_data" : voice_data ,
94+ "response_format" : response_format ,
95+ "sensitive_word_check" : sensitive_word_check ,
96+ "request_id" : request_id ,
97+ "user_id" : user_id
98+ }
99+ )
100+ files = extract_files (cast (Mapping [str , object ], body ), paths = [["voice_data" ]])
101+
102+ if files :
103+ extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
104+ return self ._post (
105+ "/audio/customization" ,
106+ body = maybe_transform (body , audio_customization_param .AudioCustomizationParam ),
107+ files = files ,
108+ options = make_request_options (
109+ extra_headers = extra_headers , extra_body = extra_body , timeout = timeout
110+ ),
111+ cast_type = _legacy_response .HttpxBinaryResponseContent
112+ )
0 commit comments