Skip to content

Expose request builder methods#889

Open
GALCF wants to merge 1 commit intoprism-php:mainfrom
GALCF:feature/expose-audio-requests
Open

Expose request builder methods#889
GALCF wants to merge 1 commit intoprism-php:mainfrom
GALCF:feature/expose-audio-requests

Conversation

@GALCF
Copy link
Contributor

@GALCF GALCF commented Feb 4, 2026

Description

The audio request now exposes its toTextToSpeechRequest and toSpeechToTextRequest methods.

This can be useful for example if you have to preprocess request data in a configurator.

Example code:

<?php

protected function preprocessAudio(): void
{
    try {
        $audio = $this->request->toSpeechToTextRequest()->input();
    } catch (InvalidArgumentException) {
        // Is not a speech-to-text request
        return;
    }

    if (!$audio->hasRawContent()) {
        // Does not have readable content
        return;
    }

    $mimeType = $audio->mimeType();
    $content  = $audio->rawContent();
    Assert::notNull($content);

    // Preprocess $content here

    $audio = Audio::fromRawContent($content, $mimeType);

    $this->request->withInput($audio);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant