કન્ટેન્ટ પર જાઓ
API key મેળવો

માર્ગદર્શિકાઓ · ઑડિયો

પવિત્ર રેકોર્ડિંગ વગાડો

રેકોર્ડિંગ ધરાવતી એન્ટ્રી માટે કામચલાઉ પ્લેબૅક URL માંગો.

આ રિક્વેસ્ટ સેન્ડબોક્સમાં અજમાવો

1 ચાલતી રિક્વેસ્ટ મોકલો

GET /v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json
curl "$MANTRILO_API_URL/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
પ્લેસહોલ્ડર URL સાથેનો દૃષ્ટાંતરૂપ રિસ્પોન્સ200 OK
{
  "data": {
    "url": "https://storage.example.com/signed-recording",
    "expiresAt": "2026-11-12T17:51:28.392Z",
    "bytes": 123077,
    "contentType": "audio/x-m4a"
  }
}

2 તેને તમારા સર્વર પરથી કૉલ કરો

key તમારા બૅકએન્ડમાં રાખો અને તમારી ઍપને ફક્ત કન્ટેન્ટ પાછું આપો. આ Node.js સર્વર એક રૂટ આપે છે જેને તમારી ઍપ કૉલ કરી શકે.

server.mjs
// server.mjs · Node.js 22+
import { createServer } from 'node:http';

const apiKey = process.env.MANTRILO_API_KEY;
if (!apiKey) throw new Error('Set MANTRILO_API_KEY on your server.');
const base = process.env.MANTRILO_API_URL ?? "https://api.mantrilo.com";

async function mantrilo(path, input) {
  const response = await fetch(base + path, {
    method: input ? 'POST' : 'GET',
    headers: {
      Authorization: 'Bearer ' + apiKey,
      ...(input ? { 'Content-Type': 'application/json' } : {}),
    },
    ...(input ? { body: JSON.stringify(input) } : {}),
    signal: AbortSignal.timeout(20000),
    redirect: 'error',
  });
  const result = await response.json();
  if (!response.ok) throw Object.assign(new Error('Mantrilo request failed'), {
    status: response.status, requestId: result.requestId,
  });
  return result;
}

async function load(incoming) {
  return mantrilo("/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json");
}

createServer(async (req, res) => {
  const incoming = new URL(req.url, 'http://localhost');
  res.setHeader('Content-Type', 'application/json');
  if (req.method !== 'GET' || incoming.pathname !== '/api/mantrilo-guide') {
    res.writeHead(404).end(JSON.stringify({ error: 'Not found' }));
    return;
  }
  try {
    const result = await load(incoming);
    res.end(JSON.stringify(result));
  } catch (error) {
    res.writeHead(error.status ?? 502).end(JSON.stringify({
      error: 'Could not load this content',
      requestId: error.requestId,
    }));
  }
}).listen(3000, '127.0.0.1');
તમારા વ્યૂમાં
document.querySelector("audio").src = data.url; // Web player; on mobile use data.url as the audio source.

3 ઇનપુટ અને પેજિનેશન

મંત્ર રેકોર્ડમાંથી audio.href વાપરો અને ?format=json ઉમેરો. જો audio null હોય, તો પ્લેયર છુપાવો. સાદો endpoint રેકોર્ડિંગ પર રીડાયરેક્ટ કરે છે. JSON મોડ તમારા બૅકએન્ડને signed URL આપે છે.

data.url તમારા પ્લેયરને આપો, અને data.expiresAt પછી નવી લિંક માંગો. ઉદાહરણ રિસ્પોન્સમાં સમયસીમા પૂરી થયેલા signed URL ની જગ્યાએ પ્લેસહોલ્ડર મૂક્યું છે.

4 ક્વોટા

દરેક સફળ લિંક જારી કરવામાં એક રિક્વેસ્ટ વપરાય છે અને ફાઇલનું આખું કદ બાઇટમાં ઑડિયો ક્વોટામાંથી ગણાય છે. પ્લેયરમાં પહેલેથી જારી થયેલું URL વાંચવાથી Mantrilo API ની નવી રિક્વેસ્ટ થતી નથી.

રિક્વેસ્ટ base URL MANTRILO_API_URL માંથી વાંચે છે. સર્વરનું ઉદાહરણ ન મળે તો https://api.mantrilo.com વાપરે છે.