MCPcopy Create free account
hub / github.com/pollinations/pollinations / generateAudio

Function generateAudio

apps/chat/src/utils/api.js:569–588  ·  view source on GitHub ↗
(text, options = {})

Source from the content-addressed store, hash-verified

567
568// Generate speech/audio — GET /audio/{text}?voice=...
569export const generateAudio = async (text, options = {}) => {
570 const { voice = "nova", model = "openai-audio" } = options;
571
572 const params = new URLSearchParams({ voice, model });
573 const url = `${BASE_URL}/audio/${encodeURIComponent(text)}?${params}`;
574 const token = getApiToken();
575 const headers = token ? { Authorization: `Bearer ${token}` } : {};
576 const response = await fetch(url, { headers });
577 if (!response.ok) throw await parseApiError(response);
578
579 const blob = await response.blob();
580 const mimeType = blob.type || "audio/mpeg";
581 return new Promise((resolve, reject) => {
582 const reader = new FileReader();
583 reader.onloadend = () =>
584 resolve({ url: reader.result, text, voice, model, mimeType });
585 reader.onerror = reject;
586 reader.readAsDataURL(blob);
587 });
588};

Callers 1

AppFunction · 0.90

Calls 4

getApiTokenFunction · 0.85
blobMethod · 0.80
parseApiErrorFunction · 0.70
fetchFunction · 0.50

Tested by

no test coverage detected