-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSTTProvider.php
More file actions
41 lines (35 loc) · 1.13 KB
/
STTProvider.php
File metadata and controls
41 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
// SPDX-FileCopyrightText: Julien Veyssier <julien-nc@posteo.net>
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\Replicate\SpeechToText;
use OCA\Replicate\Service\ReplicateAPIService;
use OCP\Files\File;
use OCP\IL10N;
use OCP\SpeechToText\ISpeechToTextProvider;
use Psr\Log\LoggerInterface;
class STTProvider implements ISpeechToTextProvider {
public function __construct(
private ReplicateAPIService $replicateAPIService,
private LoggerInterface $logger,
private IL10N $l,
) {
}
/**
* @inheritDoc
*/
public function getName(): string {
return $this->l->t('Replicate\'s Whisper Speech-To-Text');
}
/**
* @inheritDoc
*/
public function transcribeFile(File $file): string {
try {
return $this->replicateAPIService->transcribeFile($file->getContent());
} catch (\Exception $e) {
$this->logger->warning('Replicate\'s Whisper transcription of file "' . $file->getPath() .'" failed with: ' . $e->getMessage(), ['exception' => $e]);
throw new \RuntimeException('Replicate\'s Whisper transcription of file "' . $file->getPath() .'" failed with: ' . $e->getMessage());
}
}
}