|
11 | 11 |
|
12 | 12 | use OCA\OpenAi\AppInfo\Application; |
13 | 13 | use OCA\OpenAi\Service\OpenAiAPIService; |
14 | | -use OCP\IAppConfig; |
15 | | -use OCP\IL10N; |
16 | 14 | use OCP\TaskProcessing\IManager; |
| 15 | +use OCP\TaskProcessing\ISynchronousProvider; |
17 | 16 | use OCP\TaskProcessing\Task; |
| 17 | +use OCP\TaskProcessing\TaskTypes\AudioToText; |
18 | 18 | use Psr\Log\LoggerInterface; |
19 | 19 | use Throwable; |
20 | 20 |
|
21 | | -// Built on top of the AudioToTextProvider to add paragraph reformatting. |
22 | | -class AudioToTextEnhancedProvider extends AudioToTextProvider { |
23 | | - private const REFORMAT_PARAGRAPHS_TASK_TYPE_ID = 'core:text2text:reformatparagraphs'; |
24 | | - |
25 | | - private IManager $taskProcessingManager; |
| 21 | +class AudioToTextEnhancedProvider implements ISynchronousProvider { |
26 | 22 |
|
27 | 23 | public function __construct( |
28 | | - OpenAiAPIService $openAiAPIService, |
29 | | - LoggerInterface $logger, |
30 | | - IAppConfig $appConfig, |
31 | | - IL10N $l, |
32 | | - IManager $taskProcessingManager, |
| 24 | + private AudioToTextProvider $audioToTextProvider, |
| 25 | + private OpenAiAPIService $openAiAPIService, |
| 26 | + private IManager $taskProcessingManager, |
| 27 | + private LoggerInterface $logger, |
33 | 28 | ) { |
34 | | - parent::__construct($openAiAPIService, $logger, $appConfig, $l); |
35 | | - $this->taskProcessingManager = $taskProcessingManager; |
36 | 29 | } |
37 | 30 |
|
38 | 31 | public function getId(): string { |
39 | | - return parent::getId() . '-enhanced'; |
| 32 | + return $this->audioToTextProvider->getId() . '-enhanced'; |
40 | 33 | } |
41 | 34 |
|
42 | 35 | public function getName(): string { |
43 | | - return parent::getName() . ' ' . $this->l->t('(with paragraph reformatting)'); |
| 36 | + return $this->audioToTextProvider->getName() . ' (with paragraph reformatting)'; |
| 37 | + } |
| 38 | + |
| 39 | + public function getTaskTypeId(): string { |
| 40 | + return AudioToText::ID; |
| 41 | + } |
| 42 | + |
| 43 | + public function getExpectedRuntime(): int { |
| 44 | + return $this->audioToTextProvider->getExpectedRuntime(); |
| 45 | + } |
| 46 | + |
| 47 | + public function getInputShapeEnumValues(): array { |
| 48 | + return $this->audioToTextProvider->getInputShapeEnumValues(); |
| 49 | + } |
| 50 | + |
| 51 | + public function getInputShapeDefaults(): array { |
| 52 | + return $this->audioToTextProvider->getInputShapeDefaults(); |
| 53 | + } |
| 54 | + |
| 55 | + public function getOptionalInputShape(): array { |
| 56 | + return $this->audioToTextProvider->getOptionalInputShape(); |
| 57 | + } |
| 58 | + |
| 59 | + public function getOptionalInputShapeEnumValues(): array { |
| 60 | + return $this->audioToTextProvider->getOptionalInputShapeEnumValues(); |
| 61 | + } |
| 62 | + |
| 63 | + public function getOptionalInputShapeDefaults(): array { |
| 64 | + return $this->audioToTextProvider->getOptionalInputShapeDefaults(); |
| 65 | + } |
| 66 | + |
| 67 | + public function getOutputShapeEnumValues(): array { |
| 68 | + return $this->audioToTextProvider->getOutputShapeEnumValues(); |
| 69 | + } |
| 70 | + |
| 71 | + public function getOptionalOutputShape(): array { |
| 72 | + return $this->audioToTextProvider->getOptionalOutputShape(); |
| 73 | + } |
| 74 | + |
| 75 | + public function getOptionalOutputShapeEnumValues(): array { |
| 76 | + return $this->audioToTextProvider->getOptionalOutputShapeEnumValues(); |
44 | 77 | } |
45 | 78 |
|
46 | 79 | public function process(?string $userId, array $input, callable $reportProgress): array { |
47 | | - $transcription = parent::process($userId, $input, $reportProgress)['output']; |
| 80 | + $transcription = $this->audioToTextProvider->process($userId, $input, $reportProgress)['output']; |
| 81 | + |
| 82 | + // Skip reformatting if the transcription is empty |
| 83 | + if (trim($transcription) === '') { |
| 84 | + return ['output' => $transcription]; |
| 85 | + } |
48 | 86 |
|
49 | 87 | $reformatTask = new Task( |
50 | | - self::REFORMAT_PARAGRAPHS_TASK_TYPE_ID, |
| 88 | + \OCP\TaskProcessing\TaskTypes\TextToTextReformatParagraphs::ID, |
51 | 89 | ['input' => $transcription], |
52 | 90 | Application::APP_ID, |
53 | 91 | $userId, |
|
0 commit comments