Skip to content

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