Skip to content

Commit e9dddbb

Browse files
committed
Merge prism-php#1001 — fix(media): normalize wav mimeType variants to audio/wav
2 parents 346edd4 + dc20d12 commit e9dddbb

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/ValueObjects/Media/Media.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,15 @@ public function base64(): ?string
249249

250250
public function mimeType(): ?string
251251
{
252-
if ($this->mimeType) {
253-
return $this->mimeType;
254-
}
255-
256-
if ($content = $this->rawContent()) {
252+
if ($this->mimeType === null && $content = $this->rawContent()) {
257253
$this->mimeType = (new finfo(FILEINFO_MIME_TYPE))->buffer($content) ?: null;
258254
}
259255

256+
$this->mimeType = match ($this->mimeType) {
257+
'audio/x-wav', 'audio/wave', 'audio/x-pn-wav', 'audio/vnd.wave' => 'audio/wav',
258+
default => $this->mimeType,
259+
};
260+
260261
return $this->mimeType;
261262
}
262263

tests/Providers/Gemini/GeminiMediaTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function (Request $request): bool {
153153
'text' => 'Transcribe this audio',
154154
])
155155
->and($message[1]['inline_data'])->toHaveKeys(['mime_type', 'data'])
156-
->and($message[1]['inline_data']['mime_type'])->toBe('audio/x-wav')
156+
->and($message[1]['inline_data']['mime_type'])->toBe('audio/wav')
157157
->and($message[1]['inline_data']['data'])->toBe(
158158
base64_encode(file_get_contents('tests/Fixtures/sample-audio.wav'))
159159
);
@@ -171,7 +171,7 @@ function (Request $request): bool {
171171
$audioUrl => Http::response(
172172
file_get_contents('tests/Fixtures/sample-audio.wav'),
173173
200,
174-
['Content-Type' => 'audio/x-wav']
174+
['Content-Type' => 'audio/wav']
175175
),
176176
]);
177177

@@ -197,7 +197,7 @@ function (Request $request): bool {
197197
'text' => 'What is in this audio',
198198
])
199199
->and($message[1]['inline_data'])->toHaveKeys(['mime_type', 'data'])
200-
->and($message[1]['inline_data']['mime_type'])->toBe('audio/x-wav')
200+
->and($message[1]['inline_data']['mime_type'])->toBe('audio/wav')
201201
->and($message[1]['inline_data']['data'])->toBe(
202202
base64_encode(file_get_contents('tests/Fixtures/sample-audio.wav'))
203203
);

0 commit comments

Comments
 (0)