#I am using the nodejs package and I am getting this error TypeError: client.textToSpeech.convertTex
1 messages · Page 1 of 1 (latest)
Based on the information provided, it seems like you're trying to use the convertTextToSpeechStream function from the ElevenLabs SDK in Node.js. However, in the provided content, the function used for converting text to speech is convert, not convertTextToSpeechStream.
Here's an example of how to use the convert function in Node.js:
import os from 'os';
import { VoiceSettings } from 'elevenlabs';
import { ElevenLabs } from 'elevenlabs.client';
const ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY");
const client = new ElevenLabs(ELEVENLABS_API_KEY);
function text_to_speech_file(text: string) {
const response = client.text_to_speech.convert(
"pNInz6obpgDQGcFmaJgB", // Adam pre-made voice
{
optimize_streaming_latency: "0",
output_format: "mp3_22050_32",
text: text,
model_id: "eleven_turbo_v2_5", // use the turbo model for low latency
voice_settings: new VoiceSettings(
{
stability: 0.0,
similarity_boost: 1.0,
style: 0.0,
use_speaker_boost: true,
}
),
}
);
// Further processing of the response
}
You can then run this function with:
text_to_speech_file("Hello World");
Please ensure that you're using the correct function name and that your package is up-to-date. If the issue persists, it might be a good idea to check the official documentation again or reach out to the package maintainers for further assistance.
I am now getting: TypeError: Cannot destructure property 'enable_logging' of 'request' as it is undefined.
This is my code: const { ElevenLabsClient } = require("elevenlabs");
const dotenv = require("dotenv");
dotenv.config();
const ELEVENLABS_API_KEY = process.env.ELEVENLABS_API_KEY;
const VOICE_ID = process.env.ELEVENLABS_VOICE_ID;
if (!ELEVENLABS_API_KEY) {
throw new Error("ELEVENLABS_API_KEY is not set in .env file");
}
if (!VOICE_ID) {
throw new Error("ELEVENLABS_VOICE_ID is not set in .env file");
}
const client = new ElevenLabsClient({
apiKey: ELEVENLABS_API_KEY,
voiceId: VOICE_ID,
});
async function generateSpeech(text) {
try {
console.log('Generating speech for:', text);
console.log('Available methods are: ');
console.log(client.textToSpeech);
const audioStream = await client.textToSpeech.convert({
textInput: { text },
voiceId: VOICE_ID,
modelId: "eleven_multilingual_v2",
});
// Convert stream to buffer
const chunks = []
for await (const chunk of audioStream) {
chunks.push(chunk);
}
const audioBuffer = Buffer.concat(chunks);
console.log('Speech generated successfully');
return audioBuffer;
} catch (error) {
console.error('Error generating speech:', error);
throw error;
}
}
module.exports = { generateSpeech };
Based on the information provided, it seems like there might be an issue with the way the request is being structured or how the enable_logging property is being accessed. However, without more specific information from the error or the exact part of the code where this error is occurring, it's difficult to provide a precise solution.
In the provided code, I don't see where 'enable_logging' is being used or destructured. If it's part of the request object in the convert method, make sure that the request object includes the 'enable_logging' property.
Here's an example of how you might include it:
const audioStream = await client.textToSpeech.convert({
textInput: { text },
voiceId: VOICE_ID,
modelId: "eleven_multilingual_v2",
enable_logging: true, // or false, depending on your needs
});
If the error is happening elsewhere in your code, you might need to check that the 'request' object where 'enable_logging' is being destructured is defined and includes 'enable_logging'.
Remember, 'enable_logging' is a boolean and its default value is true. When 'enable_logging' is set to false, full privacy mode will be used for the request. This will mean history features are unavailable for this request, including request stitching. Full privacy mode may only be used by enterprise customers.
If the issue persists, could you please provide more details or ask a follow-up question?
I am still seeing the error : Error generating speech: TypeError: Cannot destructure property 'enable_logging' of 'request' as it is undefined.
at TextToSpeech.<anonymous> (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\node_modules\elevenlabs\api\resources\textToSpeech\client\Client.js:69:37)
at Generator.next (<anonymous>)
at C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\node_modules\elevenlabs\api\resources\textToSpeech\client\Client.js:34:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\node_modules\elevenlabs\api\resources\textToSpeech\client\Client.js:30:12)
at TextToSpeech.convert (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\node_modules\elevenlabs\apitextToSpeech\client\Client.js:30:12)
at TextToSpeech.convert (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\node_modules\elevenlabs\api\resources\textToSpeech\client\Client.js:68:16)
at generateSpeech (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\voiceCloning.js:26:51)
at Pumpify.<anonymous> (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\server.js:104:37)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Error generating cloned speech: TypeError: Cannot destructure property 'enable_logging' of 'request' as it is undefined.
at TextToSpeech.<anonymous> (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\node_modules\elevenlabs at generateSpeech
.....
at TextToSpeech.convert (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\node_modules\elevenlabs\api\resources\textToSpeech\client\Client.js:68:16)
at generateSpeech (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\voiceCloning.js:26:51)
at Pumpify.<anonymous> (C:\Users\zwzek\Desktop\Current Projects\Kalu\backend\server.js:104:37)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitting transcriptionAndTranslation event