From 145cbc21527d68613c6f4d0babe52763a8c7191f Mon Sep 17 00:00:00 2001 From: yuhongxiao Date: Fri, 5 Sep 2025 16:44:31 +0800 Subject: [PATCH] add tts param volume and speed --- src/zai/api_resource/audio/audio.py | 4 ++++ tests/integration_tests/test_audio.py | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/zai/api_resource/audio/audio.py b/src/zai/api_resource/audio/audio.py index 9523f47..92fe520 100644 --- a/src/zai/api_resource/audio/audio.py +++ b/src/zai/api_resource/audio/audio.py @@ -55,6 +55,8 @@ def speech( extra_headers: Headers | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + speed: float | None = 1.0, + volume: float | None = 1.0, ) -> HttpxBinaryResponseContent: """ Generate speech audio from text input @@ -80,6 +82,8 @@ def speech( 'sensitive_word_check': sensitive_word_check, 'request_id': request_id, 'user_id': user_id, + 'speed': speed, + 'volume': volume, } ) return self._post( diff --git a/tests/integration_tests/test_audio.py b/tests/integration_tests/test_audio.py index e143571..420f19b 100644 --- a/tests/integration_tests/test_audio.py +++ b/tests/integration_tests/test_audio.py @@ -10,12 +10,15 @@ def test_audio_speech(logging_conf): logging.config.dictConfig(logging_conf) # type: ignore client = ZaiClient() # Fill in your own API Key try: - speech_file_path = Path(__file__).parent / 'asr1.wav' + speech_file_path = Path(__file__).parent / 'asr1.pcm' response = client.audio.speech( model='cogtts', input='Hello, welcome to Z.ai Open Platform', voice='female', - response_format='wav', + response_format='pcm', + encode_format='hex', + speed=1.0, + volume=1.0, ) response.stream_to_file(speech_file_path)