FakeTranscribeProvider.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. declare(strict_types=1);
  7. namespace OCA\Testing\TaskProcessing;
  8. use OCA\Testing\AppInfo\Application;
  9. use OCP\AppFramework\Services\IAppConfig;
  10. use OCP\Files\File;
  11. use OCP\TaskProcessing\Exception\ProcessingException;
  12. use OCP\TaskProcessing\ISynchronousProvider;
  13. use OCP\TaskProcessing\TaskTypes\AudioToText;
  14. use RuntimeException;
  15. class FakeTranscribeProvider implements ISynchronousProvider {
  16. public function __construct(
  17. protected IAppConfig $appConfig,
  18. ) {
  19. }
  20. public function getId(): string {
  21. return Application::APP_ID . '-audio2text';
  22. }
  23. public function getName(): string {
  24. return 'Fake audio2text task processing provider';
  25. }
  26. public function getTaskTypeId(): string {
  27. return AudioToText::ID;
  28. }
  29. public function getExpectedRuntime(): int {
  30. return 1;
  31. }
  32. public function getInputShapeEnumValues(): array {
  33. return [];
  34. }
  35. public function getInputShapeDefaults(): array {
  36. return [];
  37. }
  38. public function getOptionalInputShape(): array {
  39. return [];
  40. }
  41. public function getOptionalInputShapeEnumValues(): array {
  42. return [];
  43. }
  44. public function getOptionalInputShapeDefaults(): array {
  45. return [];
  46. }
  47. public function getOutputShapeEnumValues(): array {
  48. return [];
  49. }
  50. public function getOptionalOutputShape(): array {
  51. return [];
  52. }
  53. public function getOptionalOutputShapeEnumValues(): array {
  54. return [];
  55. }
  56. public function process(?string $userId, array $input, callable $reportProgress): array {
  57. if (!isset($input['input']) || !$input['input'] instanceof File || !$input['input']->isReadable()) {
  58. throw new RuntimeException('Invalid input file');
  59. }
  60. if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
  61. throw new ProcessingException('Failing as set by AppConfig');
  62. }
  63. $inputFile = $input['input'];
  64. $transcription = 'Fake transcription result';
  65. return ['output' => $transcription];
  66. }
  67. }