, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> */ final class TranslationResponse implements Response { /** * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> */ use ArrayAccessible; /** * @param array $segments */ private function __construct( public readonly ?string $task, public readonly ?string $language, public readonly ?float $duration, public readonly array $segments, public readonly string $text, ) { } /** * Acts as static factory, and returns a new Response instance. * * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string} $attributes */ public static function from(array|string $attributes): self { if (is_string($attributes)) { $attributes = ['text' => $attributes]; } $segments = isset($attributes['segments']) ? array_map(fn (array $result): TranslationResponseSegment => TranslationResponseSegment::from( $result ), $attributes['segments']) : []; return new self( $attributes['task'] ?? null, $attributes['language'] ?? null, $attributes['duration'] ?? null, $segments, $attributes['text'], ); } /** * {@inheritDoc} */ public function toArray(): array { return [ 'task' => $this->task, 'language' => $this->language, 'duration' => $this->duration, 'segments' => array_map( static fn (TranslationResponseSegment $result): array => $result->toArray(), $this->segments, ), 'text' => $this->text, ]; } }