@devvai/devv-code-backend
Version:
Backend SDK for Devv Code - Provides authentication, data management, email and AI capabilities
54 lines (53 loc) • 1.96 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevvTTS = void 0;
const device_1 = require("./device");
const session_1 = require("./session");
const constants_1 = require("./constants");
/**
* DevvTTS - Text-to-Speech conversion using ElevenLabs API
*
* Converts text to natural-sounding speech using ElevenLabs service
*
* Usage:
* ```typescript
* const tts = new DevvTTS();
* const result = await tts.convert({
* text: "Hello, world!"
* });
* ```
*
* Note: Requires ElevenLabs API key to be configured externally
* For detailed parameter documentation, see: https://elevenlabs.io/docs/api-reference/text-to-speech
*/
class DevvTTS {
async convert(options) {
if (!options.text) {
throw new Error('Text is required for text-to-speech conversion');
}
const deviceId = (0, device_1.getEncryptedDeviceId)();
const sid = (0, session_1.getSid)();
const headers = {
'Content-Type': 'application/json',
'Device-Id': deviceId
};
if (sid) {
headers['sid'] = sid;
}
const response = await fetch(`${constants_1.BASE_URL}api/v1/text-to-speech`, {
method: 'POST',
headers,
body: JSON.stringify(options)
});
if (!response.ok) {
const error = await response.json().catch(() => ({ error: 'Text-to-speech conversion failed' }));
// Provide helpful error message for API key issues
if (response.status === 401 || response.status === 403) {
throw new Error('ElevenLabs API key error. Please ensure you have configured your ElevenLabs API key in the external API keys configuration.');
}
throw new Error(error.error || `Failed to convert text to speech (Status: ${response.status})`);
}
return await response.json();
}
}
exports.DevvTTS = DevvTTS;
;