33from typing import TYPE_CHECKING , Mapping , Optional , cast
44
55import httpx
6- from httpx import stream
76
87from zai .core import (
98 NOT_GIVEN ,
2322from zai .types .sensitive_word_check import SensitiveWordCheckRequest
2423
2524from .transcriptions import Transcriptions
25+ from zai .core ._streaming import StreamResponse
26+ from zai .types .audio import AudioSpeechChunk
2627
2728if TYPE_CHECKING :
2829 from zai ._client import ZaiClient
@@ -60,7 +61,7 @@ def speech(
6061 speed : float | None = 1.0 ,
6162 volume : float | None = 1.0 ,
6263 stream : bool | None = False
63- ) -> HttpxBinaryResponseContent :
64+ ) -> HttpxBinaryResponseContent | StreamResponse [ AudioSpeechChunk ] :
6465 """
6566 Generate speech audio from text input
6667
@@ -83,7 +84,6 @@ def speech(
8384 'voice' : voice ,
8485 'response_format' : response_format ,
8586 'encode_format' : encode_format ,
86- 'sensitive_word_check' : sensitive_word_check ,
8787 'request_id' : request_id ,
8888 'user_id' : user_id ,
8989 'speed' : speed ,
@@ -96,6 +96,8 @@ def speech(
9696 body = maybe_transform (body , AudioSpeechParams ),
9797 options = make_request_options (extra_headers = extra_headers , extra_body = extra_body , timeout = timeout ),
9898 cast_type = HttpxBinaryResponseContent ,
99+ stream = stream or False ,
100+ stream_cls = StreamResponse [AudioSpeechChunk ]
99101 )
100102
101103 def customization (
0 commit comments