Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelthomas5 committed May 7, 2024
1 parent a4033df commit 3cc7abf
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions examples/text-to-speech-websockets/node-express/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ io.on('connection', (socket) => {
elevenlabsSocket.send(JSON.stringify(initialMessage));
};

elevenlabsSocket.onmessage = (event: any) => {
const response = JSON.parse(event.data);
if (response.error) {
socket.emit('error', response);
}

if (response.audio) {
socket.emit('audio', response.audio);
}
};

socket.on('message', (data) => {
const message = JSON.parse(data) as { text: string; isFinal?: boolean };
const textMessage = {
Expand All @@ -60,6 +49,18 @@ io.on('connection', (socket) => {

elevenlabsSocket.send(JSON.stringify(textMessage));
});

elevenlabsSocket.onmessage = (event: any) => {
const response = JSON.parse(event.data);

if (response.error) {
socket.emit('error', response);
}

if (response.audio) {
socket.emit('audio', response.audio);
}
};
});

server.listen(PORT, () => {
Expand Down

0 comments on commit 3cc7abf

Please sign in to comment.