add async audio send
This commit is contained in:
parent
4a24727131
commit
e914c0ca14
3 changed files with 18 additions and 15 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
/* eslint @typescript-eslint/no-var-requires: "off" */
|
||||
import { sendMessage } from './session'
|
||||
import { sendAudio } from './session'
|
||||
const portAudio = require('naudiodon');
|
||||
|
||||
let ia: typeof portAudio.AudioIO;
|
||||
|
|
@ -18,7 +18,7 @@ export const updateRecorder = (_event, record: boolean): void => {
|
|||
} else {
|
||||
ia.pause();
|
||||
const audio = processAudio(audioInput);
|
||||
sendMessage(audio);
|
||||
sendAudio(audio);
|
||||
audioInput = [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,11 +66,9 @@ const receiveMessage = (message: string): void => {
|
|||
}
|
||||
|
||||
const parsed: RenderMessage = JSON.parse(message);
|
||||
console.log('received message', parsed);
|
||||
if (parsed.modifier === "sf") {
|
||||
backgroundMitt.emit('message-res', parsed);
|
||||
} else if (parsed.modifier === "ai"){
|
||||
console.log('ai message')
|
||||
backgroundMitt.emit('ipc-renderer', {
|
||||
endpoint: 'render-message',
|
||||
message: parsed
|
||||
|
|
@ -79,15 +77,17 @@ const receiveMessage = (message: string): void => {
|
|||
|
||||
};
|
||||
|
||||
export const sendMessage = (content: TextMessage | Buffer) => {
|
||||
if (content instanceof Buffer) {
|
||||
socket.send(content);
|
||||
} else if (content) {
|
||||
socket.send(JSON.stringify(content));
|
||||
}
|
||||
export const sendAudio = async (content: Buffer) => {
|
||||
|
||||
const res = await asyncSend(null, content);
|
||||
|
||||
backgroundMitt.emit('ipc-renderer', {
|
||||
endpoint: 'render-message',
|
||||
message: res
|
||||
});
|
||||
}
|
||||
|
||||
const asyncSend = (_event, payload: any): Promise<RenderMessage> => {
|
||||
const asyncSend = (_event?, payload: TextMessage | Buffer): Promise<RenderMessage> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
backgroundMitt.once('message-res', (res: RenderMessage) => {
|
||||
|
|
@ -95,11 +95,16 @@ const asyncSend = (_event, payload: any): Promise<RenderMessage> => {
|
|||
if (res.content) {
|
||||
resolve(res);
|
||||
} else {
|
||||
reject()
|
||||
reject('ERROR: NO MESSAGE');
|
||||
}
|
||||
|
||||
});
|
||||
socket.send(JSON.stringify(payload));
|
||||
|
||||
if (payload instanceof Buffer) {
|
||||
socket.send(payload);
|
||||
} else if (payload) {
|
||||
socket.send(JSON.stringify(payload));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,12 +47,10 @@ export default defineComponent({
|
|||
onMounted(() => {
|
||||
|
||||
emitter.on("renderMessage", (payload: Message | undefined) => {
|
||||
console.log('render ai message', payload)
|
||||
if (payload) renderArr.push(payload);
|
||||
});
|
||||
|
||||
emitter.on("animateSend", async (message) => {
|
||||
console.log('caught message to send', message);
|
||||
rendering.value = true;
|
||||
try {
|
||||
await invoke(message);
|
||||
|
|
|
|||
Loading…
Reference in a new issue