Skip to navigation

Change the Form of the Text

View as Markdown

Two settings change how text is written.

  • style.preset decides how much is tidied: clean (default) drops fillers and keeps only the corrected version of a self-correction, light keeps every word, none skips the finishing step.
  • style.rules is one or more plain sentences that change the form: lists, translation, ₹, 24-hour time.

The one rule to remember: style.rules change the form of text. They never add or remove content. When you need something new (an email, a summary, JSON), use output_rules.

Bullets and translation

import os
from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
BULLETS = 'Put each task on its own line, as a bullet that starts with "- ".'
with open("tasks_ta.wav", "rb") as f:
res = client.dictate.transcribe(
file=f,
language_code="ta-IN",
mode="codemix",
style={"rules": "Translate the text into English. " + BULLETS},
)
print(res.text)
Output
- I need to go to the bank.
- Then I need to phone my mother.
- After that, I need to book a rail ticket on Friday.

Rupees and 24-hour time

RUPEE = (
"Write money amounts as the ₹ sign and digits with Indian digit grouping, "
"for example ₹1,25,000. Write no currency word after the amount."
)
H24 = "Write times in 24-hour format, for example 15:30."
with open("money.wav", "rb") as f:
res = client.dictate.transcribe(
file=f,
language_code="en-IN",
style={"rules": RUPEE + " " + H24},
)
print(res.text)
Output
Please transfer ₹1,25,000 to Ravi by the 5th of December. The call with the bank is at 15:30 in the afternoon and the second one is at 21:15 at night.

Codes and digit strings

Speech recognition writes a spoken string of digits as one number: “seven, four, two” becomes 742. For a code, an OTP or a phone number, that is often wrong. Choose how you want the digits:

You wantDo thisYou get
742Nothing: this is the defaultMy phone code is 742 and the price is ₹500.
7 4 2Add a rule: Write spoken digits of a code one by one, separated by spaces, for example 7 4 2.My phone code is 7 4 2 and the price is ₹500.
seven four twoSend mode=verbatim, which keeps number words everywhereMy phone code is seven four two and the price is five hundred rupees.
import os
from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
with open("code.wav", "rb") as f:
response = client.dictate.transcribe(
file=f,
language_code="en-IN",
style={"rules": "Write spoken digits of a code one by one, separated by spaces, for example 7 4 2."},
)
print(response.text) # My phone code is 7 4 2 and the price is ₹500.

Write good rules

DoWhy
Name the change with a verb: “Translate the text into English.”A bare word such as “English.” is not a change
Say what the result looks like: Put each task on its own line, as a bullet that starts with "- ".Gives the exact marker your app needs
Choose the script with mode firstmode=translit gives Roman Hindi with no rule
Put new content in output_rulesstyle.rules cannot add it
Keep all rules in one string, one sentence each (up to 2,000 characters)style.rules is a single string

In Telugu and Tamil, number words can stay as words. Add Write every number as digits. to get digits.