mistral_common.protocol.speech.request
SpeechRequest(**data)
Bases: BaseCompletionRequest
Request for text-to-speech synthesis.
Supports both preset voices and voice cloning via reference audio.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str | None
|
Optional unique identifier for the speech request. |
model |
str | None
|
Optional model identifier for the speech synthesis. If |
input |
str
|
Text to convert to speech. |
voice |
str | None
|
Optional preset voice identifier (e.g., 'Neutral Male', 'Neutral
Female'). Ignored when |
ref_audio |
str | bytes | None
|
Optional reference audio for voice cloning, provided as a base64-encoded string or raw bytes. Takes precedence over voice when both are provided. |
Source code in pydantic/main.py
from_openai(openai_request, strict=False)
classmethod
Create a SpeechRequest from an OpenAI-compatible request dictionary.
Reference audio can be a BytesIO, a file-like object with a .file attribute, raw bytes (decoded via Audio), or an already base64-encoded string (used as-is). A dict voice ({"id": ...}) is normalized to a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_request
|
dict[str, Any]
|
Dictionary matching OpenAI's speech request schema. |
required |
strict
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
SpeechRequest
|
A SpeechRequest instance with "seed" mapped to |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If decoded reference audio has no detectable format. |
Source code in src/mistral_common/protocol/speech/request.py
to_openai(**kwargs)
Convert this SpeechRequest to an OpenAI-compatible request dictionary.
Reference audio is converted into an in-memory file buffer with the
correct format extension, and random_seed is renamed to "seed".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Additional key-value pairs merged into the output. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
An OpenAI-compatible request dictionary. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If soundfile is not installed and |