$request_options Optional. The request options. Default empty array. * @return Candidates The response candidates with generated speech - usually just one. * * @throws InvalidArgumentException Thrown if the given content is invalid. * @throws Generative_AI_Exception Thrown if the request fails or the response is invalid. */ final public function text_to_speech( $content, array $request_options = array() ): Candidates { $contents = $this->sanitize_new_content( $content ); return $this->send_text_to_speech_request( $contents, $request_options ); } /** * Sanitizes the input content for text to speech. * * @since 0.7.0 * * @param string|Parts|Content|Content[] $content The input content. * @return Content[] The sanitized content. * * @throws InvalidArgumentException Thrown if the input content is invalid. */ private function sanitize_new_content( $content ): array { $capabilities = AI_Capabilities::get_model_instance_capabilities( $this ); return Formatter::format_and_validate_new_contents( $content, $capabilities ); } /** * Sends a request to transform text to speech. * * @since 0.7.0 * * @param Content[] $contents The content to transform to speech. * @param array $request_options The request options. * @return Candidates The response candidates with generated speech - usually just one. * * @throws Generative_AI_Exception Thrown if the request fails or the response is invalid. */ abstract protected function send_text_to_speech_request( array $contents, array $request_options ): Candidates; }