From 56cc10e02fc8f0fd03c14b1065cdfe88733aa5ff Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sun, 15 Jun 2025 20:57:54 -0400 Subject: [PATCH 1/5] feat(OpenAI): Add support for streaming for transcriptions --- src/Contracts/Resources/AudioContract.php | 10 +++ src/Resources/Audio.php | 25 +++++++ src/Resources/Concerns/Streamable.php | 4 +- src/Responses/Audio/Streaming/Logprobs.php | 63 +++++++++++++++++ .../Audio/Streaming/TranscriptTextDelta.php | 69 +++++++++++++++++++ .../Audio/Streaming/TranscriptTextDone.php | 69 +++++++++++++++++++ .../Audio/TranscriptionStreamResponse.php | 64 +++++++++++++++++ 7 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 src/Responses/Audio/Streaming/Logprobs.php create mode 100644 src/Responses/Audio/Streaming/TranscriptTextDelta.php create mode 100644 src/Responses/Audio/Streaming/TranscriptTextDone.php create mode 100644 src/Responses/Audio/TranscriptionStreamResponse.php diff --git a/src/Contracts/Resources/AudioContract.php b/src/Contracts/Resources/AudioContract.php index dda91572..3bff4262 100644 --- a/src/Contracts/Resources/AudioContract.php +++ b/src/Contracts/Resources/AudioContract.php @@ -5,6 +5,7 @@ use OpenAI\Responses\Audio\SpeechStreamResponse; use OpenAI\Responses\Audio\TranscriptionResponse; use OpenAI\Responses\Audio\TranslationResponse; +use OpenAI\Responses\StreamResponse; interface AudioContract { @@ -35,6 +36,15 @@ public function speechStreamed(array $parameters): SpeechStreamResponse; */ public function transcribe(array $parameters): TranscriptionResponse; + /** + * Transcribes audio input the streamed events. + * + * @see https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-stream + * + * @param array $parameters + */ + public function transcribeStreamed(array $parameters): StreamResponse; + /** * Translates audio into English. * diff --git a/src/Resources/Audio.php b/src/Resources/Audio.php index 57d535e3..c3cb6e9f 100644 --- a/src/Resources/Audio.php +++ b/src/Resources/Audio.php @@ -7,12 +7,15 @@ use OpenAI\Contracts\Resources\AudioContract; use OpenAI\Responses\Audio\SpeechStreamResponse; use OpenAI\Responses\Audio\TranscriptionResponse; +use OpenAI\Responses\Audio\TranscriptionStreamResponse; use OpenAI\Responses\Audio\TranslationResponse; +use OpenAI\Responses\StreamResponse; use OpenAI\ValueObjects\Transporter\Payload; use OpenAI\ValueObjects\Transporter\Response; final class Audio implements AudioContract { + use Concerns\Streamable; use Concerns\Transportable; /** @@ -24,6 +27,8 @@ final class Audio implements AudioContract */ public function speech(array $parameters): string { + $this->ensureNotStreamed($parameters, 'speechStreamed'); + $payload = Payload::create('audio/speech', $parameters); return $this->transporter->requestContent($payload); @@ -54,6 +59,8 @@ public function speechStreamed(array $parameters): SpeechStreamResponse */ public function transcribe(array $parameters): TranscriptionResponse { + $this->ensureNotStreamed($parameters, 'transcribeStreamed'); + $payload = Payload::upload('audio/transcriptions', $parameters); /** @var Response, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient?: bool}>, words: array, text: string}> $response */ @@ -62,6 +69,24 @@ public function transcribe(array $parameters): TranscriptionResponse return TranscriptionResponse::from($response->data(), $response->meta()); } + /** + * Transcribes audio input the streamed events. + * + * @see https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-stream + * + * @param array $parameters + */ + public function transcribeStreamed(array $parameters): StreamResponse + { + $parameters = $this->setStreamParameter($parameters); + + $payload = Payload::upload('audio/transcriptions', $parameters); + + $response = $this->transporter->requestStream($payload); + + return new StreamResponse(TranscriptionStreamResponse::class, $response); + } + /** * Translates audio into English. * diff --git a/src/Resources/Concerns/Streamable.php b/src/Resources/Concerns/Streamable.php index a6362984..8540bac7 100644 --- a/src/Resources/Concerns/Streamable.php +++ b/src/Resources/Concerns/Streamable.php @@ -9,7 +9,7 @@ trait Streamable /** * @param array $parameters */ - private function ensureNotStreamed(array $parameters): void + private function ensureNotStreamed(array $parameters, string $fallbackFunction = 'createStreamed'): void { if (! isset($parameters['stream'])) { return; @@ -19,7 +19,7 @@ private function ensureNotStreamed(array $parameters): void return; } - throw new InvalidArgumentException('Stream option is not supported. Please use the createStreamed() method instead.'); + throw new InvalidArgumentException("Stream option is not supported. Please use the $fallbackFunction() method instead."); } /** diff --git a/src/Responses/Audio/Streaming/Logprobs.php b/src/Responses/Audio/Streaming/Logprobs.php new file mode 100644 index 00000000..b72404f1 --- /dev/null +++ b/src/Responses/Audio/Streaming/Logprobs.php @@ -0,0 +1,63 @@ +, logprobs: int, token: string} + * + * @implements ResponseContract + */ +final class Logprobs implements ResponseContract, ResponseHasMetaInformationContract +{ + /** + * @use ArrayAccessible + */ + use ArrayAccessible; + + use Fakeable; + use HasMetaInformation; + + /** + * @param array $bytes + */ + private function __construct( + public readonly array $bytes, + public readonly int $logprobs, + public readonly string $token, + public readonly MetaInformation $meta, + ) {} + + /** + * @param LogprobsType $attributes + */ + public static function from(array $attributes, MetaInformation $meta): self + { + return new self( + bytes: $attributes['bytes'], + logprobs: $attributes['logprobs'], + token: $attributes['token'], + meta: $meta, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'bytes' => $this->bytes, + 'logprobs' => $this->logprobs, + 'token' => $this->token, + ]; + } +} diff --git a/src/Responses/Audio/Streaming/TranscriptTextDelta.php b/src/Responses/Audio/Streaming/TranscriptTextDelta.php new file mode 100644 index 00000000..eb39f3ff --- /dev/null +++ b/src/Responses/Audio/Streaming/TranscriptTextDelta.php @@ -0,0 +1,69 @@ +, delta: string} + * + * @implements ResponseContract + */ +final class TranscriptTextDelta implements ResponseContract, ResponseHasMetaInformationContract +{ + /** + * @use ArrayAccessible + */ + use ArrayAccessible; + + use Fakeable; + use HasMetaInformation; + + private function __construct( + public readonly ?array $logprobs, + public readonly string $delta, + public readonly MetaInformation $meta, + ) {} + + /** + * @param TranscriptTextDeltaType $attributes + */ + public static function from(array $attributes, MetaInformation $meta): self + { + if (isset($attributes['logprobs'])) { + $logprobs = array_map( + fn (array $logprob): Logprobs => Logprobs::from($logprob, $meta), + $attributes['logprobs'] + ); + } + + return new self( + logprobs: $logprobs ?? null, + delta: $attributes['delta'], + meta: $meta, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'logprobs' => $this->logprobs ? array_map( + fn (Logprobs $logprob): array => $logprob->toArray(), + $this->logprobs + ) : null, + 'delta' => $this->delta, + ]; + } +} diff --git a/src/Responses/Audio/Streaming/TranscriptTextDone.php b/src/Responses/Audio/Streaming/TranscriptTextDone.php new file mode 100644 index 00000000..fc10ef56 --- /dev/null +++ b/src/Responses/Audio/Streaming/TranscriptTextDone.php @@ -0,0 +1,69 @@ +, text: string} + * + * @implements ResponseContract + */ +final class TranscriptTextDone implements ResponseContract, ResponseHasMetaInformationContract +{ + /** + * @use ArrayAccessible + */ + use ArrayAccessible; + + use Fakeable; + use HasMetaInformation; + + private function __construct( + public readonly ?array $logprobs, + public readonly string $text, + public readonly MetaInformation $meta, + ) {} + + /** + * @param TranscriptTextDoneType $attributes + */ + public static function from(array $attributes, MetaInformation $meta): self + { + if (isset($attributes['logprobs'])) { + $logprobs = array_map( + fn (array $logprob): Logprobs => Logprobs::from($logprob, $meta), + $attributes['logprobs'] + ); + } + + return new self( + logprobs: $logprobs ?? null, + text: $attributes['text'], + meta: $meta, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'logprobs' => $this->logprobs ? array_map( + fn (Logprobs $logprob): array => $logprob->toArray(), + $this->logprobs + ) : null, + 'text' => $this->text, + ]; + } +} diff --git a/src/Responses/Audio/TranscriptionStreamResponse.php b/src/Responses/Audio/TranscriptionStreamResponse.php new file mode 100644 index 00000000..4719be40 --- /dev/null +++ b/src/Responses/Audio/TranscriptionStreamResponse.php @@ -0,0 +1,64 @@ +} + * + * @implements ResponseContract + */ +final class TranscriptionStreamResponse implements ResponseContract +{ + /** + * @use ArrayAccessible + */ + use ArrayAccessible; + + use FakeableForStreamedResponse; + + private function __construct( + public readonly string $event, + public readonly mixed $response, + ) {} + + /** + * @param array $attributes + */ + public static function from(array $attributes): self + { + $event = $attributes['type'] ?? throw new UnknownEventException('Missing event type in streamed response'); + $meta = $attributes['__meta']; + unset($attributes['__meta']); + + $response = match ($event) { + 'transcript.text.delta' => TranscriptTextDelta::from($attributes, $meta), // @phpstan-ignore-line + 'transcript.text.done' => TranscriptTextDone::from($attributes, $meta), // @phpstan-ignore-line + default => throw new UnknownEventException('Unknown Responses streaming event: '.$event), + }; + + return new self( + event: $event, // @phpstan-ignore-line + response: $response, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'event' => $this->event, + 'data' => $this->response->toArray(), + ]; + } +} From 6ca7103f1cc935e1dca4204cfbeeeed9a8ea2f90 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Mon, 16 Jun 2025 08:01:27 -0400 Subject: [PATCH 2/5] test(OpenAI): Add support for streaming for transcriptions --- src/Testing/Resources/AudioTestResource.php | 6 +++++ tests/Fixtures/Audio.php | 8 ++++++ .../Streams/AudioTranscriptionTranscribe.txt | 12 +++++++++ tests/Resources/Audio.php | 25 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 tests/Fixtures/Streams/AudioTranscriptionTranscribe.txt diff --git a/src/Testing/Resources/AudioTestResource.php b/src/Testing/Resources/AudioTestResource.php index b3fd2820..7f31e266 100644 --- a/src/Testing/Resources/AudioTestResource.php +++ b/src/Testing/Resources/AudioTestResource.php @@ -7,6 +7,7 @@ use OpenAI\Responses\Audio\SpeechStreamResponse; use OpenAI\Responses\Audio\TranscriptionResponse; use OpenAI\Responses\Audio\TranslationResponse; +use OpenAI\Responses\StreamResponse; use OpenAI\Testing\Resources\Concerns\Testable; final class AudioTestResource implements AudioContract @@ -33,6 +34,11 @@ public function transcribe(array $parameters): TranscriptionResponse return $this->record(__FUNCTION__, func_get_args()); } + public function transcribeStreamed(array $parameters): StreamResponse + { + return $this->record(__FUNCTION__, func_get_args()); + } + public function translate(array $parameters): TranslationResponse { return $this->record(__FUNCTION__, func_get_args()); diff --git a/tests/Fixtures/Audio.php b/tests/Fixtures/Audio.php index 96771698..13347a83 100644 --- a/tests/Fixtures/Audio.php +++ b/tests/Fixtures/Audio.php @@ -188,3 +188,11 @@ function speechStream() { return fopen(__DIR__.'/Streams/Speech.mp3', 'r'); } + +/** + * @return resource + */ +function audioTranscriptionStream() +{ + return fopen(__DIR__.'/Streams/AudioTranscriptionTranscribe.txt', 'r'); +} diff --git a/tests/Fixtures/Streams/AudioTranscriptionTranscribe.txt b/tests/Fixtures/Streams/AudioTranscriptionTranscribe.txt new file mode 100644 index 00000000..0c084a1c --- /dev/null +++ b/tests/Fixtures/Streams/AudioTranscriptionTranscribe.txt @@ -0,0 +1,12 @@ +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":"The"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" quick"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" brown"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" fox"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" jumps"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" over"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" the"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" lazy"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" dog"}} +data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":"."}} +data: {"event":"transcript.text.done","data":{"logprobs":null,"text":"The quick brown fox jumps over the lazy dog."}} + diff --git a/tests/Resources/Audio.php b/tests/Resources/Audio.php index daaeac95..81532968 100644 --- a/tests/Resources/Audio.php +++ b/tests/Resources/Audio.php @@ -102,6 +102,31 @@ ->toBeInstanceOf(MetaInformation::class); }); +test('transcribe to text streaming', function () { + $response = new Response( + headers: metaHeaders(), + body: new Stream(audioTranscriptionStream()), + ); + + $client = mockStreamClient('POST', 'audio/transcriptions', [ + 'file' => audioFileResource(), + 'model' => 'gpt-4o-transcribe', + 'stream' => true, + ], $response); + + $result = $client->audio()->transcribeStreamed([ + 'file' => audioFileResource(), + 'model' => 'gpt-4o-transcribe', + ]); + + expect($result) + ->toBeInstanceOf(SpeechStreamResponse::class) + ->toBeInstanceOf(IteratorAggregate::class); + + expect($result->getIterator()) + ->toBeInstanceOf(Iterator::class); +}); + test('translate to text', function () { $client = mockClient('POST', 'audio/translations', [ 'file' => audioFileResource(), From 8acb4679f94c844c0b9775bf2f58973d81241b41 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Mon, 16 Jun 2025 08:50:07 -0400 Subject: [PATCH 3/5] fix(OpenAI): Add transcription support streaming --- README.md | 15 ++++++++++++ src/Contracts/Resources/AudioContract.php | 2 ++ src/Resources/Audio.php | 1 + .../Audio/Streaming/TranscriptTextDelta.php | 3 +++ .../Audio/Streaming/TranscriptTextDone.php | 3 +++ .../Streams/AudioTranscriptionTranscribe.txt | 24 +++++++++---------- tests/Resources/Audio.php | 20 ++++++++++------ 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7c6adc8a..b7428cc4 100644 --- a/README.md +++ b/README.md @@ -671,6 +671,21 @@ foreach ($response->words as $word) { $response->toArray(); // ['task' => 'transcribe', ...] ``` +#### `transcribe streamed` + +Transcribes audio into the input language with streaming. + +```php +$stream = OpenAI::audio()->transcribeStreamed([ + 'model' => 'gpt-4o-transcribe', + 'file' => fopen('audio.mp3', 'r'), +]); + +foreach ($stream as $event) { + echo json_encode($event->toArray()); // {"event":"transcript.text.delta","data":{"delta":"The"}} +} +``` + #### `translate` Translates audio into English. diff --git a/src/Contracts/Resources/AudioContract.php b/src/Contracts/Resources/AudioContract.php index 3bff4262..04ea8afc 100644 --- a/src/Contracts/Resources/AudioContract.php +++ b/src/Contracts/Resources/AudioContract.php @@ -4,6 +4,7 @@ use OpenAI\Responses\Audio\SpeechStreamResponse; use OpenAI\Responses\Audio\TranscriptionResponse; +use OpenAI\Responses\Audio\TranscriptionStreamResponse; use OpenAI\Responses\Audio\TranslationResponse; use OpenAI\Responses\StreamResponse; @@ -42,6 +43,7 @@ public function transcribe(array $parameters): TranscriptionResponse; * @see https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-stream * * @param array $parameters + * @return StreamResponse */ public function transcribeStreamed(array $parameters): StreamResponse; diff --git a/src/Resources/Audio.php b/src/Resources/Audio.php index c3cb6e9f..3e3f7218 100644 --- a/src/Resources/Audio.php +++ b/src/Resources/Audio.php @@ -75,6 +75,7 @@ public function transcribe(array $parameters): TranscriptionResponse * @see https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-stream * * @param array $parameters + * @return StreamResponse */ public function transcribeStreamed(array $parameters): StreamResponse { diff --git a/src/Responses/Audio/Streaming/TranscriptTextDelta.php b/src/Responses/Audio/Streaming/TranscriptTextDelta.php index eb39f3ff..fbd9656c 100644 --- a/src/Responses/Audio/Streaming/TranscriptTextDelta.php +++ b/src/Responses/Audio/Streaming/TranscriptTextDelta.php @@ -28,6 +28,9 @@ final class TranscriptTextDelta implements ResponseContract, ResponseHasMetaInfo use Fakeable; use HasMetaInformation; + /** + * @param array|null $logprobs + */ private function __construct( public readonly ?array $logprobs, public readonly string $delta, diff --git a/src/Responses/Audio/Streaming/TranscriptTextDone.php b/src/Responses/Audio/Streaming/TranscriptTextDone.php index fc10ef56..9f4b2f37 100644 --- a/src/Responses/Audio/Streaming/TranscriptTextDone.php +++ b/src/Responses/Audio/Streaming/TranscriptTextDone.php @@ -28,6 +28,9 @@ final class TranscriptTextDone implements ResponseContract, ResponseHasMetaInfor use Fakeable; use HasMetaInformation; + /** + * @param array|null $logprobs + */ private function __construct( public readonly ?array $logprobs, public readonly string $text, diff --git a/tests/Fixtures/Streams/AudioTranscriptionTranscribe.txt b/tests/Fixtures/Streams/AudioTranscriptionTranscribe.txt index 0c084a1c..5a7c8d68 100644 --- a/tests/Fixtures/Streams/AudioTranscriptionTranscribe.txt +++ b/tests/Fixtures/Streams/AudioTranscriptionTranscribe.txt @@ -1,12 +1,12 @@ -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":"The"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" quick"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" brown"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" fox"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" jumps"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" over"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" the"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" lazy"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":" dog"}} -data: {"event":"transcript.text.delta","data":{"logprobs":null,"delta":"."}} -data: {"event":"transcript.text.done","data":{"logprobs":null,"text":"The quick brown fox jumps over the lazy dog."}} - +data: {"type":"transcript.text.delta","delta":"The"} +data: {"type":"transcript.text.delta","delta":" quick"} +data: {"type":"transcript.text.delta","delta":" brown"} +data: {"type":"transcript.text.delta","delta":" fox"} +data: {"type":"transcript.text.delta","delta":" jumps"} +data: {"type":"transcript.text.delta","delta":" over"} +data: {"type":"transcript.text.delta","delta":" the"} +data: {"type":"transcript.text.delta","delta":" lazy"} +data: {"type":"transcript.text.delta","delta":" dog"} +data: {"type":"transcript.text.delta","delta":"."} +data: {"type":"transcript.text.done","text":"The quick brown fox jumps over the lazy dog."} +data: [DONE] diff --git a/tests/Resources/Audio.php b/tests/Resources/Audio.php index 81532968..574ff214 100644 --- a/tests/Resources/Audio.php +++ b/tests/Resources/Audio.php @@ -5,9 +5,11 @@ use OpenAI\Responses\Audio\SpeechStreamResponse; use OpenAI\Responses\Audio\TranscriptionResponse; use OpenAI\Responses\Audio\TranscriptionResponseSegment; +use OpenAI\Responses\Audio\TranscriptionStreamResponse; use OpenAI\Responses\Audio\TranslationResponse; use OpenAI\Responses\Audio\TranslationResponseSegment; use OpenAI\Responses\Meta\MetaInformation; +use OpenAI\Responses\StreamResponse; test('transcribe to text', function () { $client = mockClient('POST', 'audio/transcriptions', [ @@ -112,7 +114,7 @@ 'file' => audioFileResource(), 'model' => 'gpt-4o-transcribe', 'stream' => true, - ], $response); + ], $response, false); $result = $client->audio()->transcribeStreamed([ 'file' => audioFileResource(), @@ -120,11 +122,15 @@ ]); expect($result) - ->toBeInstanceOf(SpeechStreamResponse::class) - ->toBeInstanceOf(IteratorAggregate::class); - - expect($result->getIterator()) + ->toBeInstanceOf(StreamResponse::class) + ->toBeInstanceOf(IteratorAggregate::class) + ->and($result->getIterator()) ->toBeInstanceOf(Iterator::class); + + foreach ($result as $event) { + expect($event) + ->toBeInstanceOf(TranscriptionStreamResponse::class); + } }); test('translate to text', function () { @@ -240,15 +246,15 @@ test('text to speech streamed', function () { $response = new Response( - body: new Stream(speechStream()), headers: metaHeaders(), + body: new Stream(speechStream()), ); $client = mockStreamClient('POST', 'audio/speech', [ 'model' => 'tts-1', 'input' => 'Hello, how are you?', 'voice' => 'alloy', - ], $response, 'requestContent'); + ], $response); $result = $client->audio()->speechStreamed([ 'model' => 'tts-1', From 74225b27a817fddd256714ab7378a1a3a81f401b Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Mon, 16 Jun 2025 08:56:13 -0400 Subject: [PATCH 4/5] fix(OpenAI): Add transcription support streaming --- src/Responses/Audio/Streaming/TranscriptTextDelta.php | 4 ++-- src/Responses/Audio/Streaming/TranscriptTextDone.php | 4 ++-- src/Responses/Audio/TranscriptionStreamResponse.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Responses/Audio/Streaming/TranscriptTextDelta.php b/src/Responses/Audio/Streaming/TranscriptTextDelta.php index fbd9656c..dfe58c74 100644 --- a/src/Responses/Audio/Streaming/TranscriptTextDelta.php +++ b/src/Responses/Audio/Streaming/TranscriptTextDelta.php @@ -14,7 +14,7 @@ /** * @phpstan-import-type LogprobsType from Logprobs * - * @phpstan-type TranscriptTextDeltaType array{logprobs: array, delta: string} + * @phpstan-type TranscriptTextDeltaType array{logprobs?: array|null, delta: string} * * @implements ResponseContract */ @@ -29,7 +29,7 @@ final class TranscriptTextDelta implements ResponseContract, ResponseHasMetaInfo use HasMetaInformation; /** - * @param array|null $logprobs + * @param array|null $logprobs */ private function __construct( public readonly ?array $logprobs, diff --git a/src/Responses/Audio/Streaming/TranscriptTextDone.php b/src/Responses/Audio/Streaming/TranscriptTextDone.php index 9f4b2f37..1d36f75e 100644 --- a/src/Responses/Audio/Streaming/TranscriptTextDone.php +++ b/src/Responses/Audio/Streaming/TranscriptTextDone.php @@ -14,7 +14,7 @@ /** * @phpstan-import-type LogprobsType from Logprobs * - * @phpstan-type TranscriptTextDoneType array{logprobs?: array, text: string} + * @phpstan-type TranscriptTextDoneType array{logprobs?: array|null, text: string} * * @implements ResponseContract */ @@ -29,7 +29,7 @@ final class TranscriptTextDone implements ResponseContract, ResponseHasMetaInfor use HasMetaInformation; /** - * @param array|null $logprobs + * @param array|null $logprobs */ private function __construct( public readonly ?array $logprobs, diff --git a/src/Responses/Audio/TranscriptionStreamResponse.php b/src/Responses/Audio/TranscriptionStreamResponse.php index 4719be40..99bdf650 100644 --- a/src/Responses/Audio/TranscriptionStreamResponse.php +++ b/src/Responses/Audio/TranscriptionStreamResponse.php @@ -27,7 +27,7 @@ final class TranscriptionStreamResponse implements ResponseContract private function __construct( public readonly string $event, - public readonly mixed $response, + public readonly TranscriptTextDelta|TranscriptTextDone $response, ) {} /** From d2c1df76bf414a45a3f99f6a549dc8a1acd46853 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Mon, 16 Jun 2025 20:00:14 -0400 Subject: [PATCH 5/5] chore: remove Responses from Audio transcribe --- src/Responses/Audio/TranscriptionStreamResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Responses/Audio/TranscriptionStreamResponse.php b/src/Responses/Audio/TranscriptionStreamResponse.php index 99bdf650..b7664efb 100644 --- a/src/Responses/Audio/TranscriptionStreamResponse.php +++ b/src/Responses/Audio/TranscriptionStreamResponse.php @@ -42,7 +42,7 @@ public static function from(array $attributes): self $response = match ($event) { 'transcript.text.delta' => TranscriptTextDelta::from($attributes, $meta), // @phpstan-ignore-line 'transcript.text.done' => TranscriptTextDone::from($attributes, $meta), // @phpstan-ignore-line - default => throw new UnknownEventException('Unknown Responses streaming event: '.$event), + default => throw new UnknownEventException('Unknown Audio Transcription streaming event: '.$event), }; return new self(