Skip to content
Open
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
11 changes: 6 additions & 5 deletions src/ValueObjects/Media/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,15 @@ public function base64(): ?string

public function mimeType(): ?string
{
if ($this->mimeType) {
return $this->mimeType;
}

if ($content = $this->rawContent()) {
if ($this->mimeType === null && $content = $this->rawContent()) {
$this->mimeType = (new finfo(FILEINFO_MIME_TYPE))->buffer($content) ?: null;
}

$this->mimeType = match ($this->mimeType) {
'audio/x-wav', 'audio/wave', 'audio/x-pn-wav', 'audio/vnd.wave' => 'audio/wav',
default => $this->mimeType,
};

return $this->mimeType;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Providers/Gemini/GeminiMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function (Request $request): bool {
'text' => 'Transcribe this audio',
])
->and($message[1]['inline_data'])->toHaveKeys(['mime_type', 'data'])
->and($message[1]['inline_data']['mime_type'])->toBe('audio/x-wav')
->and($message[1]['inline_data']['mime_type'])->toBe('audio/wav')
->and($message[1]['inline_data']['data'])->toBe(
base64_encode(file_get_contents('tests/Fixtures/sample-audio.wav'))
);
Expand All @@ -171,7 +171,7 @@ function (Request $request): bool {
$audioUrl => Http::response(
file_get_contents('tests/Fixtures/sample-audio.wav'),
200,
['Content-Type' => 'audio/x-wav']
['Content-Type' => 'audio/wav']
),
]);

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