-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
116 lines (99 loc) · 3.49 KB
/
app.js
File metadata and controls
116 lines (99 loc) · 3.49 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import fs from 'fs';
import { Configuration, OpenAIApi } from 'openai';
import AudioRecorder from 'node-audiorecorder';
import dotenv from 'dotenv';
dotenv.config();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
// Options for the audio recorder
const options = {
program: 'sox',
device: null,
bits: 16,
channels: 1,
encoding: 'signed-integer',
rate: 16000,
type: 'wav',
};
// Record audio
function recordAudio(filename) {
const audioRecorder = new AudioRecorder(options);
const outputStream = fs.createWriteStream(filename);
console.log('Recording... Press Ctrl+C to stop.');
audioRecorder.start().stream().pipe(outputStream);
process.on('SIGINT', () => {
audioRecorder.stop();
});
}
// Transcribe audio
async function transcribeAudio(filename) {
const transcript = await openai.createTranscription(
fs.createReadStream(filename),
'whisper-1',
undefined,
undefined,
undefined,
'fr'
);
return transcript.data.text;
}
// Summarize transcript
async function summarizeTranscript(context, transcript) {
const prompt = `${context}\nVoici le transcript de la réunion:\n${transcript}`;
const messages = [
{
role: 'user',
content:
"J'aimerais que tu prennes le rôle d'un scribe de réunion, tu devras rédiger un compte rendu qui résume le transcript que tu receveras en entrée.",
},
{
role: 'assistant',
content:
"Bien sûr, je suis tout à fait capable d'accomplir cette tâche. N'hésitez pas à me donner un exemple de transcript sur lequel je peux travailler pour générer un compte rendu.",
},
{
role: 'user',
content: prompt,
},
];
console.log('Prompt:\n' + messages.map((message) => `${message.role[0].toUpperCase() + message.role.slice(1)}: ${message.content}`).join('\n\n'));
const summary = await openai.createChatCompletion({
model: 'gpt-3.5-turbo-16k-0613',
messages,
});
return summary.data.choices[0];
}
async function loadContext() {
const baseContext = fs.readFileSync('./templates/base_context', 'utf8');
const context = fs.readFileSync(process.argv[2], 'utf8');
return `${baseContext}\n${context}`;
}
// Main function
async function main() {
const today = new Date();
const DD = today.getDate() < 10 ? `0${today.getDate()}` : today.getDate();
const MM = today.getMonth() + 1 < 10 ? `0${today.getMonth() + 1}` : today.getMonth() + 1;
const YYYY = today.getFullYear();
const todayDDMMYYYY = `${DD}-${MM}-${YYYY}`;
if (!fs.existsSync(`./records`)) fs.mkdirSync(`./records`);
const audioFilename = `./records/conversation-${todayDDMMYYYY}.wav`;
recordAudio(audioFilename);
// Read context from file passed as argument
const context = await loadContext();
process.on('SIGINT', async () => {
const transcription = await transcribeAudio(audioFilename);
console.log('\n\n\nTranscription:', transcription);
const summary = await summarizeTranscript(context, transcription);
console.log('\n\n\nCompte rendu:\n', summary.message.content);
process.exit(0);
});
while (true) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
main().catch((err) => {
console.error('An error occurred', err);
process.exit(1);
});