Skip to navigation

Adjust the loudness

View as Markdown

The loudness parameter scales the volume of the generated audio. Values below 1.0 make it quieter and values above 1.0 make it louder.

ParameterTypeRangeDefaultModelsAPIs
loudnessnumber0.1–2.51.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",
loudness=1.5,
)
save(response, "output.wav")

loudness 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",
loudness=1.5, # louder 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 waveform amplitude scales with the value. In a short test, 0.1 produced audio at roughly a tenth of the default peak level, while 2.0 and 2.5 reached full scale, so very high values can clip.

If you need more volume, raise it in small steps and check for distortion, or normalize the audio in your player or pipeline instead.

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
loudness above 2.5For the Bulbul V3 and V4 models, loudness should be between 0.1 and 2.5
loudness below 0.1Validation Error(s): - loudness: Input should be greater than or equal to 0.1

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