Skip to content
Merged
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
3 changes: 2 additions & 1 deletion lib/TaskProcessing/AudioToTextSubtitlesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\Exception\ProcessingException;
use OCP\TaskProcessing\Exception\UserFacingProcessingException;
use OCP\TaskProcessing\FileShaped;
use OCP\TaskProcessing\ISynchronousProvider;
use OCP\TaskProcessing\ShapeDescriptor;
use OCP\TaskProcessing\ShapeEnumValue;
Expand Down Expand Up @@ -162,7 +163,7 @@ public function process(?string $userId, array $input, callable $reportProgress)

try {
$transcription = $this->openAiAPIService->transcribeFile($userId, $this->service, $inputFile, false, $model, $language, $format);
return ['output' => $transcription];
return ['output' => new FileShaped(EShapeType::File, $transcription, $format)];
} catch (UserFacingProcessingException $e) {
throw $e;
} catch (\Throwable $e) {
Expand Down
59 changes: 59 additions & 0 deletions tests/unit/Service/FileFormatDetectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\OpenAi\Tests\Unit\Service;

use OCA\OpenAi\Service\FileFormatDetector;
use PHPUnit\Framework\TestCase;

class FileFormatDetectorTest extends TestCase {
public static function imageProvider(): array {
return [
'jpeg' => ["\xFF\xD8\xFF\xE0" . str_repeat("\0", 32), 'jpeg'],
'png' => ["\x89PNG\r\n\x1A\n" . str_repeat("\0", 32), 'png'],
'gif' => ['GIF89a' . str_repeat("\0", 32), 'gif'],
'webp' => ["RIFF\x00\x00\x00\x00WEBPVP8 ", 'webp'],
'unknown' => ['garbage', ''],
'too short' => ['x', ''],
];
}

/**
* @dataProvider imageProvider
*/
public function testGetImageExtension(string $data, string $expected): void {
$this->assertSame($expected, FileFormatDetector::getImageExtension($data));
}

public static function audioProvider(): array {
return [
'mp3 with ID3 tag' => ["ID3\x04\x00" . str_repeat("\0", 32), 'mp3'],
'mp3 MPEG-1 Layer III' => ["\xFF\xFB\x90\x44" . str_repeat("\0", 32), 'mp3'],
'mp3 MPEG-2 Layer III' => ["\xFF\xF3\x00\x00" . str_repeat("\0", 32), 'mp3'],
'mp3 MPEG-2.5 Layer III' => ["\xFF\xE3\x00\x00" . str_repeat("\0", 32), 'mp3'],
'adts aac MPEG-4' => ["\xFF\xF1\x50\x80" . str_repeat("\0", 32), 'aac'],
'adts aac MPEG-2' => ["\xFF\xF9\x50\x80" . str_repeat("\0", 32), 'aac'],
'reserved mpeg version' => ["\xFF\xE8" . str_repeat("\0", 32), ''],
'wav' => ["RIFF\x24\x00\x00\x00WAVEfmt ", 'wav'],
'ogg' => ["OggS\x00\x02", 'ogg'],
'flac' => ["fLaC\x00\x00\x00\x22", 'flac'],
'm4a' => ["\x00\x00\x00\x20ftypM4A \x00\x00\x00\x00", 'm4a'],
'mp4' => ["\x00\x00\x00\x20ftypisom\x00\x00\x02\x00", 'mp4'],
'unknown' => ['garbage', ''],
'too short' => ['x', ''],
];
}

/**
* @dataProvider audioProvider
*/
public function testGetAudioExtension(string $data, string $expected): void {
$this->assertSame($expected, FileFormatDetector::getAudioExtension($data));
}
}
Loading