diff --git a/src/Exceptions/ContentBlocksException.php b/src/Exceptions/ContentBlocksException.php new file mode 100644 index 00000000..d95e4336 --- /dev/null +++ b/src/Exceptions/ContentBlocksException.php @@ -0,0 +1,9 @@ +client = new Client([ + 'base_uri' => $this->baseUri, + 'headers' => [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'Authorization' => 'Bearer ' . $this->key, + ] + ]); + } + + public function trascribe(string $filePath): string + { + // Preparar los datos del formulario + $multipart = [ + [ + 'name' => 'file', + 'contents' => fopen($filePath, 'r'), + 'filename' => basename($filePath) + ], + [ + 'name' => 'model', + 'contents' => $this->model + ], + [ + 'name' => 'language', + 'contents' => $this->language + ], + [ + 'name' => 'response_format', + 'contents' => 'json' + ] + ]; + $response = $this->client->post('', [ + 'multipart' => $multipart, + RequestOptions::TIMEOUT => 60, + RequestOptions::CONNECT_TIMEOUT => 30 + ]); + + // Procesar la respuesta + $statusCode = $response->getStatusCode(); + $body = $response->getBody()->getContents(); + $result = json_decode($body, true); + + if ($statusCode !== 200) { + throw new ProviderException('Whisper API error: ' . $body); + } + + return $result['text'] ?? ''; + } +} diff --git a/src/Transcribe/ResolveTranscribeProvider.php b/src/Transcribe/ResolveTranscribeProvider.php new file mode 100644 index 00000000..c3d0f085 --- /dev/null +++ b/src/Transcribe/ResolveTranscribeProvider.php @@ -0,0 +1,23 @@ +transcribeProvider; + } + + public function resolveTranscribeProvider(): TranscribeProviderInterface + { + if (!isset($this->embeddingsProvider)) { + $this->transcribeProvider = $this->transcribe(); + } + return $this->transcribeProvider; + } +} diff --git a/src/Transcribe/Transcribe.php b/src/Transcribe/Transcribe.php new file mode 100644 index 00000000..0630de35 --- /dev/null +++ b/src/Transcribe/Transcribe.php @@ -0,0 +1,30 @@ +sourceType->value === SourceType::URL) { + return $this->resolveTranscribeProvider()->trascribe($audio->source); + } + throw new ContentBlocksException('Unsupported audio source'); + } +} diff --git a/src/Transcribe/TranscribeProviderInterface.php b/src/Transcribe/TranscribeProviderInterface.php new file mode 100644 index 00000000..76a376dd --- /dev/null +++ b/src/Transcribe/TranscribeProviderInterface.php @@ -0,0 +1,10 @@ +