-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevenLabs.js
38 lines (32 loc) · 1.29 KB
/
elevenLabs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const axios = require('axios');
const fs = require('fs-extra');
const FormData = require('form-data');
const voice = require('elevenlabs-node');
const apiKey = '';
const voiceID = '4VdIvfguz4gfq2ADAVVa';
const fileName = 'audio.mp3';
const textInput = 'GeneratedByPrompt';
const londBreedLLMPrompt = 'Write a brief and empathetic message in the style of a mayor addressing a resident who reported an issue. The message should convey sympathy and the importance of reporting the issue. The message should end with an assurance of prompt action to fix the situation.';
const endpoint = 'https://better311.com/';
voice.textToSpeech(apiKey, voiceID, fileName, textInput)
.then((res) => {
console.log('Audio file created:', res);
const fileStream = fs.createReadStream(fileName);
const formData = new FormData();
formData.append('file', fileStream);
axios.post(endpoint, formData, {
headers: {
...formData.getHeaders(),
'Authorization': 'Bearer your-token', // If authorization is required
},
})
.then((response) => {
console.log('File sent successfully:', response.data);
})
.catch((error) => {
console.error('Error sending the file:', error);
});
})
.catch((error) => {
console.error('Error creating audio file:', error);
});