# client.speech

> The speech methods of the morevoice Python SDK: Transcribe short audio files and turn text into voice notes.

Transcribe short audio files and turn text into voice notes. These methods are on `client.speech`, where `client` is a `MoreVoice` client (see [the Python SDK](https://docs.morevoice.ai/sdk/python/#connect)). On `AsyncMoreVoice` the same methods are awaited. Each one returns the response object and raises an exception when the API answers with an error.

## `synthesize()`

**Synthesize a voice note.** Speaks up to 2000 characters in a voice from `GET /v1/voices` and returns an OGG/Opus file (`audio/ogg; codecs=opus`, mono, 48 kHz) that plays as a WhatsApp voice note. The `Audio-Duration-Ms` header gives its length and `Audio-Source` says whether it is `speech` or test mode's `synthetic` tone. Billed per character. With an `Idempotency-Key`, a retry within 24 hours returns the same file and is not billed again. Test-mode keys get a synthetic tone as long as the speech would be (the same bytes for the same request) and are never billed.

```python
# client.speech
def synthesize(self, body: _m.SynthesisCreateParamsInput | Mapping[str, Any], *, more_voice_version: str | Unset = UNSET, idempotency_key: str | Unset = UNSET) -> bytes
```

`client.speech.synthesize()` · `await async_client.speech.synthesize()` · `POST /speech/synthesis` · [API reference](https://docs.morevoice.ai/api/operations/speech_synthesize/)

### Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `text` | `string` | yes | What to say, up to 2000 characters (longer text is refused with 422 `text_too_long`). Billed per character. |
| `voice_id` | `string` | yes | The voice (`voice_id` from `GET /v1/voices`, your custom voices included). |
| `format` | `"ogg_opus"` | no | The audio format: `ogg_opus` (the default), mono 48 kHz, playable as a WhatsApp voice note. |
| `language` | `string` | no | The language of `text` (default: Hebrew when the text is in Hebrew script, else English). |

### Returns

Nothing, on success.

### Example

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

data = client.speech.synthesize({
    "format": "ogg_opus",
    "language": "he",
    "text": "שלום! ההזמנה שלך יצאה היום ותגיע מחר.",
    "voice_id": "Kore",
})
print(len(data), "bytes")
```

## `transcribe()`

**Transcribe an audio file.** Transcribes a short audio file, such as a WhatsApp voice note: OGG/Opus, WebM/Opus, WAV, MP3 or MP4/AAC, up to 16 MB and 10 minutes, as multipart/form-data (a `file` part) or as JSON with the file base64. Billed per started second of audio; audio with no speech (422 `no_speech`), audio over `max_duration_sec` (422 `audio_too_long`) and unsupported files (415 `unsupported_audio`) are not billed. The audio is processed in memory and not stored. With an `Idempotency-Key`, a retry within 24 hours returns the first result and is not billed again. Test-mode keys get a fixed sample transcript in the requested language (after the same format and length checks) and are never billed.

```python
# client.speech
def transcribe(self, body: _m.TranscriptionCreateParamsInput | _m.SpeechTranscribeFilesBody | Mapping[str, Any] | Unset = UNSET, *, more_voice_version: str | Unset = UNSET, idempotency_key: str | Unset = UNSET) -> _m.Transcription
```

`client.speech.transcribe()` · `await async_client.speech.transcribe()` · `POST /speech/transcriptions` · [API reference](https://docs.morevoice.ai/api/operations/speech_transcribe/)

### Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | `object` | yes | The audio: OGG/Opus (a WhatsApp voice note), WebM/Opus, WAV, MP3 or MP4/AAC. JSON requests send it base64; multipart/form-data requests send a `file` part. |
| `language` | `string` | no | The language spoken, as a hint (`he`, `en`, …). Without it the language is detected among the platform's default languages. |
| `max_duration_sec` | `integer` | no | The longest audio to accept, in seconds (default and maximum 600). Longer audio is refused with 422 `audio_too_long` and nothing is billed. |
| `purpose` | `"voice_note"` | no | What the audio is (`voice_note`); informational. |

### Returns

`Transcription`:

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | This transcription's ID (prefix `stx_`); quote it to support. The result is kept only to replay an `Idempotency-Key` retry (24 hours). |
| `object` | `"speech.transcription"` | Always `speech.transcription`. |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `text` | `string` | What was said. |
| `language` | `string \| null` | The language of the transcript: the hint when one was sent, else the detected language (null when none was detected). |
| `duration_sec` | `number` | The audio's length in seconds. Billed per started second. |

### Example

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

transcription = client.speech.transcribe({
    "file": {
        "content_base64": "T2dnUwACAAAAAAAAAAA=",
        "content_type": "audio/ogg",
        "filename": "note.ogg",
    },
    "language": "he",
    "max_duration_sec": 180,
    "purpose": "voice_note",
})
print(transcription)
```
