Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "zhipuai"
version = "2.1.5.20250726"
version = "2.1.5.20250801"
description = "A SDK library for accessing big model apis from ZhipuAI"
authors = ["Zhipu AI"]
readme = "README.md"
Expand Down
58 changes: 29 additions & 29 deletions tests/integration_tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@ def test_audio_speech(logging_conf):
print(err)

def test_audio_speech_streaming(logging_conf):
logging.config.dictConfig(logging_conf) # type: ignore
client = ZhipuAI() # 填写您自己的APIKey
try:
response = client.audio.speech(
model='cogtts',
input='你好呀,欢迎来到智谱开放平台',
voice='tongtong',
stream=True,
response_format='wav',
)
with open("output.pcm", "wb") as f:
for item in response:
choice = item.choices[0]
index = choice.index
finish_reason = choice.finish_reason
audio_delta = choice.delta.content
if finish_reason is not None:
break
f.write(base64.b64decode(audio_delta))
print(f"{index}.finish_reason = {finish_reason}, audio_delta = {len(audio_delta)}")

except zhipuai.core._errors.APIRequestFailedError as err:
print(err)
except zhipuai.core._errors.APIInternalError as err:
print(err)
except zhipuai.core._errors.APIStatusError as err:
print(err)
except Exception as e:
print(e)
logging.config.dictConfig(logging_conf) # type: ignore
client = ZhipuAI() # 填写您自己的APIKey
try:
response = client.audio.speech(
model='cogtts',
input='你好呀,欢迎来到智谱开放平台',
voice='tongtong',
stream=True,
response_format='mp3',
encode_format='hex'
)
with open("output.mp3", "wb") as f:
for item in response:
choice = item.choices[0]
index = choice.index
finish_reason = choice.finish_reason
audio_delta = choice.delta.content
if finish_reason is not None:
break
f.write(bytes.fromhex(audio_delta))
print(f"audio delta: {audio_delta[:64]}..., 长度:{len(audio_delta)}")
except zhipuai.core._errors.APIRequestFailedError as err:
print(err)
except zhipuai.core._errors.APIInternalError as err:
print(err)
except zhipuai.core._errors.APIStatusError as err:
print(err)
except Exception as e:
print(e)


def test_audio_customization(logging_conf):
Expand Down
4 changes: 3 additions & 1 deletion zhipuai/api_resource/audio/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def speech(
extra_headers: Headers | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
encode_format: str,
) -> _legacy_response.HttpxBinaryResponseContent | StreamResponse[AudioSpeechChunk]:
body = deepcopy_minimal(
{
Expand All @@ -61,7 +62,8 @@ def speech(
"response_format": response_format,
"sensitive_word_check": sensitive_word_check,
"request_id": request_id,
"user_id": user_id
"user_id": user_id,
"encode_format": encode_format
}
)
return self._post(
Expand Down
Loading