Skip to content

Commit c944a25

Browse files
authored
Revert "feat: tts streaming (#90)"
This reverts commit 0d314d2.
1 parent 361f779 commit c944a25

File tree

3 files changed

+5
-76
lines changed

3 files changed

+5
-76
lines changed

tests/integration_tests/test_audio.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import base64
2-
import json
31
import logging
42
import logging.config
53
from pathlib import Path
@@ -16,8 +14,7 @@ def test_audio_speech(logging_conf):
1614
response = client.audio.speech(
1715
model='cogtts',
1816
input='你好呀,欢迎来到智谱开放平台',
19-
voice='tongtong',
20-
stream=False,
17+
voice='female',
2118
response_format='wav',
2219
)
2320
response.stream_to_file(speech_file_path)
@@ -29,37 +26,6 @@ def test_audio_speech(logging_conf):
2926
except zhipuai.core._errors.APIStatusError as err:
3027
print(err)
3128

32-
def test_audio_speech_streaming(logging_conf):
33-
logging.config.dictConfig(logging_conf) # type: ignore
34-
client = ZhipuAI() # 填写您自己的APIKey
35-
try:
36-
response = client.audio.speech(
37-
model='cogtts',
38-
input='你好呀,欢迎来到智谱开放平台',
39-
voice='tongtong',
40-
stream=True,
41-
response_format='wav',
42-
)
43-
with open("output.pcm", "wb") as f:
44-
for item in response:
45-
choice = item.choices[0]
46-
index = choice.index
47-
finish_reason = choice.finish_reason
48-
audio_delta = choice.delta.content
49-
if finish_reason is not None:
50-
break
51-
f.write(base64.b64decode(audio_delta))
52-
print(f"{index}.finish_reason = {finish_reason}, audio_delta = {len(audio_delta)}")
53-
54-
except zhipuai.core._errors.APIRequestFailedError as err:
55-
print(err)
56-
except zhipuai.core._errors.APIInternalError as err:
57-
print(err)
58-
except zhipuai.core._errors.APIStatusError as err:
59-
print(err)
60-
except Exception as e:
61-
print(e)
62-
6329

6430
def test_audio_customization(logging_conf):
6531
logging.config.dictConfig(logging_conf)

zhipuai/api_resource/audio/audio.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from zhipuai.types.audio import AudioSpeechParams
1010
from ...types.audio import audio_customization_param
1111

12-
from zhipuai.core import BaseAPI, maybe_transform, StreamResponse
12+
from zhipuai.core import BaseAPI, maybe_transform
1313
from zhipuai.core import NOT_GIVEN, Body, Headers, NotGiven, FileTypes
1414
from zhipuai.core import _legacy_response
1515

@@ -20,7 +20,6 @@
2020
make_request_options,
2121
)
2222
from zhipuai.core import deepcopy_minimal
23-
from ...types.audio.audio_speech_chunk import AudioSpeechChunk
2423

2524
if TYPE_CHECKING:
2625
from zhipuai._client import ZhipuAI
@@ -47,17 +46,15 @@ def speech(
4746
sensitive_word_check: Optional[SensitiveWordCheckRequest] | NotGiven = NOT_GIVEN,
4847
request_id: str = None,
4948
user_id: str = None,
50-
stream: bool = False,
5149
extra_headers: Headers | None = None,
5250
extra_body: Body | None = None,
5351
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
54-
) -> _legacy_response.HttpxBinaryResponseContent | StreamResponse[AudioSpeechChunk]:
52+
) -> _legacy_response.HttpxBinaryResponseContent:
5553
body = deepcopy_minimal(
5654
{
5755
"model": model,
5856
"input": input,
5957
"voice": voice,
60-
"stream": stream,
6158
"response_format": response_format,
6259
"sensitive_word_check": sensitive_word_check,
6360
"request_id": request_id,
@@ -66,13 +63,11 @@ def speech(
6663
)
6764
return self._post(
6865
"/audio/speech",
69-
body=body,
66+
body=maybe_transform(body, AudioSpeechParams),
7067
options=make_request_options(
7168
extra_headers=extra_headers, extra_body=extra_body, timeout=timeout
7269
),
73-
cast_type=_legacy_response.HttpxBinaryResponseContent,
74-
stream= stream or False,
75-
stream_cls=StreamResponse[AudioSpeechChunk]
70+
cast_type=_legacy_response.HttpxBinaryResponseContent
7671
)
7772

7873
def customization(

zhipuai/types/audio/audio_speech_chunk.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)