add audio playback + buf split function

This commit is contained in:
riqo 2021-03-04 16:56:59 -06:00
commit 31e097b27f
3 changed files with 67 additions and 44 deletions

View file

@ -3,11 +3,12 @@
import WebSocket from 'ws';
import { backgroundMitt } from './emitter';
import { ipcMain } from "electron";
import { play } from './audio';
interface RenderMessage {
content: {
text: string;
audio: boolean | Buffer;
audio: string;
};
context: string;
modifier: string;
@ -67,8 +68,10 @@ const receiveMessage = (message: string): void => {
}
const parsed: RenderMessage = JSON.parse(message);
console.log('message received', parsed);
console.log('message received', parsed.content.text);
if (parsed.content.audio) {
console.log('audio received');
play(parsed.content.audio);
}
backgroundMitt.emit('ipc-renderer', {
endpoint: 'render-message',
@ -78,10 +81,12 @@ const receiveMessage = (message: string): void => {
};
const sendMessage = (_event, payload: TextMessage): void => {
console.log('sending message')
socket.send(JSON.stringify(payload));
}
export const sendAudio = (content: Buffer) => {
console.log('sending audio')
socket.send(content);
}