pyrit.prompt_target.OpenAITTSTarget#

class OpenAITTSTarget(*, voice: Literal['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] = 'alloy', response_format: Literal['flac', 'mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'ogg', 'wav', 'webm'] = 'mp3', language: str | None = 'en', speed: float | None = None, api_version: str = '2024-05-01-preview', **kwargs)[source]#

Bases: OpenAITarget

__init__(*, voice: Literal['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] = 'alloy', response_format: Literal['flac', 'mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'ogg', 'wav', 'webm'] = 'mp3', language: str | None = 'en', speed: float | None = None, api_version: str = '2024-05-01-preview', **kwargs)[source]#

Initialize the TTS target with specified parameters.

Parameters:
  • model_name (str, Optional) – The name of the model. Defaults to “tts-1”.

  • endpoint (str, Optional) – The target URL for the OpenAI service.

  • api_key (str, Optional) – The API key for accessing the Azure OpenAI service. Defaults to the AZURE_OPENAI_CHAT_KEY environment variable.

  • headers (str, Optional) – Headers of the endpoint (JSON).

  • use_aad_auth (bool, Optional) – When set to True, user authentication is used instead of API Key. DefaultAzureCredential is taken for https://cognitiveservices.azure.com/.default . Please run az login locally to leverage user AuthN.

  • api_version (str, Optional) – The version of the Azure OpenAI API. Defaults to “2024-06-01”.

  • max_requests_per_minute (int, Optional) – Number of requests the target can handle per minute before hitting a rate limit. The number of requests sent to the target will be capped at the value provided.

  • httpx_client_kwargs (dict, Optional) – Additional kwargs to be passed to the httpx.AsyncClient() constructor.

  • voice (str, Optional) – The voice to use for TTS. Defaults to “alloy”.

  • response_format (str, Optional) – The format of the audio response. Defaults to “mp3”.

  • language (str, Optional) – The language for TTS. Defaults to “en”.

  • speed (float, Optional) – The speed of the TTS. Select a value from 0.25 to 4.0. 1.0 is normal.

Methods

__init__(*[, voice, response_format, ...])

Initialize the TTS target with specified parameters.

dispose_db_engine()

Dispose DuckDB database engine to release database connections and resources.

get_identifier()

is_json_response_supported()

Indicates that this target supports JSON response format.

is_response_format_json(request_piece)

Checks if the response format is JSON and ensures the target supports it.

send_prompt_async(**kwargs)

Sends a normalized prompt async to the prompt target.

set_system_prompt(*, system_prompt, ...[, ...])

Sets the system prompt for the prompt target.

Attributes

api_key_environment_variable: str#
endpoint_environment_variable: str#
is_json_response_supported() bool[source]#

Indicates that this target supports JSON response format.

model_name_environment_variable: str#
async send_prompt_async(**kwargs)#

Sends a normalized prompt async to the prompt target.