fix audio stream shutdown

This commit is contained in:
riqo 2021-04-26 07:22:38 -05:00
commit 7c2f3cad8c
2 changed files with 24 additions and 14 deletions

View file

@ -40,7 +40,7 @@ const onRecordingEnd = async (_event: any, payload: any) => {
try { try {
resolve(audioContainer.input); resolve(audioContainer.input);
record = false; record = false;
} catch (e) { } catch (e) {
reject() reject()
} }
@ -120,7 +120,7 @@ export function play(input: string): void {
// Format the audio. // Format the audio.
const audio = bufSplit( const audio = bufSplit(
Buffer.from(input as string, 'hex'), Buffer.from(input as string, 'hex'),
8192 8192
); );
@ -165,15 +165,24 @@ export function play(input: string): void {
// ------------------------------------------------------------- // -------------------------------------------------------------
// Get's called on window close. // Get's called on window close.
// export function stopStream() { export async function stopStream() {
// console.log("AUDIO:Stopping audio stream.") console.log("AUDIO:Stopping audio stream.")
// if (ai) { if (ai) {
// ai.quit() try {
// } await ai.quit()
// if (ao) { } catch(e){
// ao.quit() console.log('AUDIO: Failed to shutdown audio input.');
// } throw e;
// console.log("AUDIO:Audio closed.") }
// } }
if (ao) {
try {
await ao.quit()
} catch(e){
console.log('AUDIO: Failed to shutdown audio output.');
throw e;
}
}
}

View file

@ -4,7 +4,7 @@
import { app, dialog } from "electron"; import { app, dialog } from "electron";
import { createWindow } from './window'; import { createWindow } from './window';
import { initSession } from './session'; import { initSession } from './session';
import { initAudioIO } from './audio'; import { initAudioIO, stopStream } from './audio';
import { backgroundMitt } from '@/modules/emitter'; import { backgroundMitt } from '@/modules/emitter';
let win: boolean; let win: boolean;
@ -63,7 +63,8 @@ export function initApp(dev: boolean): void {
}); });
// Must keep to ensure app doesn't quit on close. // Must keep to ensure app doesn't quit on close.
app.on("before-quit", () => { app.on("before-quit", async () => {
await stopStream();
}); });
// Must keep to ensure app doesn't quit on close. // Must keep to ensure app doesn't quit on close.