Introduction

This document provides examples and usage of few of the common APIs provided by Sarvam AI.

Speech to Text API

Sample CURL:

curl --location 'https://api.sarvam.ai/speech-to-text' \
--header 'api-subscription-key: 000' \
--form 'file=@/Users/adityam/Downloads/hindiAudiosTest/ta/1719_ta.wav;type=audio/wav' \
--form 'model=saarika:v1' \
--form 'language_code=ta-IN'
--form 'with_timestamps=false'

Sample Python Code:

url = "https://api.sarvam.ai/speech-to-text"

payload = {'model': 'saarika:v1',
'language_code': 'hi-IN',
'with_timesteps': 'false'}
files=[
  ('file',('1719_hi.wav',open('/Users/adityam/Downloads/hindiAudiosTest/hi/1719_hi.wav','rb'),'audio/wav'))
]
headers = {
  'api-subscription-key': '000'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

Speech to Text Translate API

Sample CURL:

curl --location 'https://api.sarvam.ai/speech-to-text-translate' \
--header 'api-subscription-key: 000' \
--form 'file=@/Users/adityam/Downloads/hindiAudiosTest/ta/1719_ta.wav;type=audio/wav' \
--form 'model=saaras:v1' \
--form 'prompt=hello'

Sample Python Code:

url = "https://api.sarvam.ai/speech-to-text-translate"

payload = {'model': 'saaras:v1',
'prompt': ''}
files=[
('file',('1719_hi.wav',open('/Users/adityam/Downloads/hindiAudiosTest/hi/1719_hi.wav','rb'),'audio/wav'))
]
headers = {
'api-subscription-key': '000'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

Text To Speech API

Sample CURL:

curl --request POST \
--url https://api.sarvam.ai/text-to-speech \
--header 'Content-Type: application/json' \
--data '{
"inputs": [
"<string>"
],
"target_language_code": "hi-IN",
"speaker": "meera",
"speech_sample_rate": 8000,
"enable_preprocessing": true,
"model": "bulbul:v1"
}'

Sample Python Code:

import requests

url = "https://api.sarvam.ai/text-to-speech"

payload = {
"inputs": ["<string>"],
"target_language_code": "hi-IN",
"speaker": "meera",
"speech_sample_rate": 8000,
"enable_preprocessing": True,
"model": "bulbul:v1"
}
headers = {"Content-Type": "application/json"}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)