Skip to content

stream param to Speech and AsyncSpeech #724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 12 additions & 3 deletions src/openai/resources/audio/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import to_raw_response_wrapper, async_to_raw_response_wrapper
from ...types.audio import speech_create_params
from ..._base_client import HttpxBinaryResponseContent, make_request_options
from ..._base_client import HttpxBinaryResponseContent, make_request_options, Stream, AsyncStream

#NOTE: this would probably be nice as some kind of Audio or SpeechCompletion Chunk, but those don't exist in the lib, this works now
from ...types.chat.chat_completion_chunk import ChatCompletionChunk

if TYPE_CHECKING:
from ..._client import OpenAI, AsyncOpenAI
Expand Down Expand Up @@ -41,7 +44,8 @@ def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> HttpxBinaryResponseContent:
stream: bool = False
) -> HttpxBinaryResponseContent | Stream[ChatCompletionChunk]:
"""
Generates audio from the input text.

Expand Down Expand Up @@ -84,6 +88,8 @@ def create(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=HttpxBinaryResponseContent,
stream=stream,
stream_cls=Stream[ChatCompletionChunk]
)


Expand All @@ -108,7 +114,8 @@ async def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> HttpxBinaryResponseContent:
stream: bool = False
) -> HttpxBinaryResponseContent | AsyncStream[ChatCompletionChunk]:
"""
Generates audio from the input text.

Expand Down Expand Up @@ -151,6 +158,8 @@ async def create(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=HttpxBinaryResponseContent,
stream=stream,
stream_cls=AsyncStream[ChatCompletionChunk]
)


Expand Down