ਗਾਈਡਾਂ · ਆਡੀਓ
ਪਵਿੱਤਰ ਰਿਕਾਰਡਿੰਗ ਚਲਾਓ
ਰਿਕਾਰਡਿੰਗ ਵਾਲੀ ਐਂਟਰੀ ਲਈ ਅਸਥਾਈ ਪਲੇਬੈਕ 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 ਮੋਡ ਤੁਹਾਡੇ ਬੈਕਐਂਡ ਨੂੰ ਸਾਈਨ ਕੀਤਾ URL ਦਿੰਦਾ ਹੈ।
data.url ਆਪਣੇ ਪਲੇਅਰ ਨੂੰ ਦਿਓ, ਅਤੇ data.expiresAt ਤੋਂ ਬਾਅਦ ਨਵਾਂ ਲਿੰਕ ਮੰਗੋ। ਉਦਾਹਰਨ ਜਵਾਬ ਵਿੱਚ ਮਿਆਦ ਪੁੱਗ ਚੁੱਕੇ ਸਾਈਨ ਕੀਤੇ URL ਦੀ ਥਾਂ ਪਲੇਸਹੋਲਡਰ ਰੱਖਿਆ ਗਿਆ ਹੈ।
4 ਕੋਟਾ
ਹਰ ਸਫਲ ਲਿੰਕ ਜਾਰੀ ਕਰਨ 'ਤੇ ਇੱਕ ਬੇਨਤੀ ਲੱਗਦੀ ਹੈ ਅਤੇ ਫ਼ਾਈਲ ਦਾ ਪੂਰਾ ਆਕਾਰ ਬਾਈਟਾਂ ਵਿੱਚ ਆਡੀਓ ਕੋਟੇ ਵਿੱਚੋਂ ਕੱਟਿਆ ਜਾਂਦਾ ਹੈ। ਪਲੇਅਰ ਵਿੱਚ ਪਹਿਲਾਂ ਜਾਰੀ ਕੀਤਾ URL ਪੜ੍ਹਨ ਨਾਲ ਕੋਈ ਨਵੀਂ Mantrilo API ਬੇਨਤੀ ਨਹੀਂ ਹੁੰਦੀ।
ਬੇਨਤੀਆਂ ਬੇਸ URL MANTRILO_API_URL ਤੋਂ ਪੜ੍ਹਦੀਆਂ ਹਨ। ਸਰਵਰ ਉਦਾਹਰਨ ਵਿੱਚ ਇਸ ਦੇ ਨਾ ਹੋਣ 'ਤੇ https://api.mantrilo.com ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ।
