- Python
- Python (Async)
def infill_create(client: Cartesia) -> None:
"""Create infill audio between two clips."""
from pathlib import Path
# Can pass file paths directly (as Path objects)
response = client.tts.infill(
model_id="sonic-3",
language="en",
transcript="Infill text",
left_audio=Path("left.wav"),
right_audio=Path("right.wav"),
voice_id="6ccbfb76-1fc6-48f7-b71d-91ac6298247b",
output_format={"container": "wav", "encoding": "pcm_f32le", "sample_rate": 44100},
)
response.write_to_file("infill_output.wav")
print(f"Saved audio to infill_output.wav")
print(f"Play with: ffplay -f wav infill_output.wav")
async def infill_create_async(client: AsyncCartesia) -> None:
"""Create infill audio between two clips."""
from pathlib import Path
response = await client.tts.infill(
model_id="sonic-3",
language="en",
transcript="Infill text",
left_audio=Path("left.wav"),
right_audio=Path("right.wav"),
voice_id="6ccbfb76-1fc6-48f7-b71d-91ac6298247b",
output_format={"container": "raw", "encoding": "pcm_f32le", "sample_rate": 44100},
)
await response.write_to_file("infill_output_async.wav")
print("Saved audio to infill_output_async.wav")
print("Play with: ffplay -f wav infill_output_async.wav")
Run this example
- Python
- Python (Async)
cd cartesia-python
CARTESIA_API_KEY=YOUR_KEY python3 examples/examples.py infill_create
cd cartesia-python
CARTESIA_API_KEY=YOUR_KEY python3 examples/async_examples.py infill_create_async