ഉള്ളടക്കത്തിലേക്ക് പോകുക
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 നിങ്ങളുടെ സെർവറിൽ നിന്ന് വിളിക്കുക

കീ നിങ്ങളുടെ ബാക്കെൻഡിൽ സൂക്ഷിച്ച് ഉള്ളടക്കം മാത്രം ആപ്പിലേക്ക് തിരികെ നൽകുക. ഈ 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 മോഡ് നിങ്ങളുടെ ബാക്കെൻഡിന് സൈൻ ചെയ്ത URL നൽകുന്നു.

data.url നിങ്ങളുടെ പ്ലെയറിന് നൽകുക, data.expiresAt കഴിഞ്ഞാൽ പുതിയ ലിങ്ക് റിക്വസ്റ്റ് ചെയ്യുക. ഉദാഹരണ റെസ്പോൺസിൽ, കാലഹരണപ്പെട്ട സൈൻ ചെയ്ത URL-ന് പകരം ഒരു പ്ലേസ്‌ഹോൾഡർ നൽകിയിരിക്കുന്നു.

4 ക്വോട്ട

വിജയകരമായി നൽകുന്ന ഓരോ ലിങ്കും ഒരു റിക്വസ്റ്റ് ഉപയോഗിക്കുകയും ഫയലിന്റെ മുഴുവൻ വലുപ്പം ബൈറ്റുകളായി ഓഡിയോ ക്വോട്ടയിൽ നിന്ന് കുറയ്ക്കുകയും ചെയ്യുന്നു. ഇതിനകം നൽകിയ URL പ്ലെയറിൽ ഉപയോഗിക്കുന്നത് പുതിയ Mantrilo API റിക്വസ്റ്റ് ഉണ്ടാക്കുന്നില്ല.

റിക്വസ്റ്റുകൾ ബേസ് URL MANTRILO_API_URL-ൽ നിന്ന് വായിക്കുന്നു. സെർവർ ഉദാഹരണം ബദലായി https://api.mantrilo.com ഉപയോഗിക്കുന്നു.