வழிகாட்டிகள் · ஒலி
புனித ஒலிப்பதிவை இயக்குங்கள்
ஒலிப்பதிவு உள்ள பதிவுக்குத் தற்காலிக இயக்க URL-ஐக் கோருங்கள்.
இந்தக் கோரிக்கையைச் சாண்ட்பாக்ஸில் முயன்று பாருங்கள்1 செயல்படும் கோரிக்கையை உருவாக்குங்கள்
curl "$MANTRILO_API_URL/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio?format=json" \
-H "Authorization: Bearer $MANTRILO_API_KEY"{
"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 · 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-க்குப் பதிலாக, எடுத்துக்காட்டுப் பதிலில் ஒரு மாதிரி URL உள்ளது.
4 ஒதுக்கீடு
வெற்றிகரமான ஒவ்வொரு இணைப்பு வழங்கலும் ஒரு கோரிக்கையைப் பயன்படுத்தும்; கோப்பின் முழு அளவும் பைட்டுகளில் ஒலி ஒதுக்கீட்டிலிருந்து கழிக்கப்படும். ஏற்கெனவே வழங்கப்பட்ட URL-ஐ பிளேயர் படிப்பது புதிய Mantrilo API கோரிக்கை எதையும் செய்யாது.
கோரிக்கைகள் base URL-ஐ MANTRILO_API_URL-இலிருந்து படிக்கின்றன. சர்வர் எடுத்துக்காட்டு மாற்றாக https://api.mantrilo.com-ஐப் பயன்படுத்தும்.
