Skip to content

Expose request builder methods#889

Merged
sixlive merged 1 commit intoprism-php:mainfrom
GALCF:feature/expose-audio-requests
Feb 26, 2026
Merged

Expose request builder methods#889
sixlive merged 1 commit intoprism-php:mainfrom
GALCF:feature/expose-audio-requests

Conversation

@GALCF
Copy link
Copy Markdown
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);
}

@sixlive sixlive merged commit ef06ebc into prism-php:main Feb 26, 2026
14 checks passed
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.

2 participants