Skip to navigation

Adjust the pace

View as Markdown

The pace parameter sets how fast the speech is delivered. Values below 1.0 slow it down and values above 1.0 speed it up.

ParameterTypeRangeDefaultModelsAPIs
pacenumber0.5–2.01.0bulbul:v4-flash, bulbul:v3REST, HTTP stream, WebSocket

Example

import os
from sarvamai import SarvamAI
from sarvamai.play import save
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
response = client.text_to_speech.convert(
text="Welcome to Sarvam AI!",
language_code="en-IN",
model="bulbul:v4-flash",
speaker="simran_en_customer",
pace=1.5,
)
save(response, "output.wav")

pace is set in the configure message and applies to every convert call that follows. The Python SDK names the language argument target_language_code; it is sent as language_code.

import asyncio
import base64
import os
from sarvamai import AsyncSarvamAI, AudioOutput
async def main():
client = AsyncSarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
async with client.text_to_speech_streaming.connect(model="bulbul:v4-flash") as ws:
await ws.configure(
target_language_code="en-IN",
speaker="simran_en_customer",
pace=1.5, # faster than normal
)
await ws.convert("Welcome to Sarvam AI!")
await ws.flush()
with open("output.mp3", "wb") as f:
async for message in ws:
if isinstance(message, AudioOutput):
f.write(base64.b64decode(message.data.audio))
asyncio.run(main())

What changes in the output

The same sentence takes longer at lower values and finishes sooner at higher values.

Suggested values

paceFeelTypical use
0.5–0.7Very slow, deliberateAccessibility tools, pronunciation guides
0.8–0.9RelaxedTutorials, narration, wellness content
1.0Natural (default)Conversational agents, general use
1.1–1.2Slightly briskNotifications, news briefings, IVR
1.3–2.0FastSpeed-listening, quick summaries

Start at 1.0 and change it in steps of 0.1. Listen to the result before going above 1.5.

Common errors

Out-of-range values are rejected with HTTP 400 on REST. On WebSocket, the error arrives as a JSON message with code 422 or 400 instead.

RequestError
pace below 0.5 or above 2.0For the Bulbul V3 and V4 models, pace should be between 0.5 and 2.0
pace is not a numberValidation Error(s): - pace: Input should be a valid number, unable to parse string as a number

On WebSocket, send a new configure message to change pace mid-session. Text still in the buffer is flushed first, then the new settings apply.