]> Repos - mime-chat/commitdiff
audio playback
authorAndrew Gundersen <gundersena@xavier.edu>
Sat, 6 Mar 2021 16:53:04 +0000 (10:53 -0600)
committerAndrew Gundersen <gundersena@xavier.edu>
Sat, 6 Mar 2021 20:01:12 +0000 (14:01 -0600)
src/background/audio.ts
src/background/session.ts
src/components/content.vue

index 313f6f1574e5a3831ae4d37c4958af83838756be..f2671773d5ff068f3fc495d73be154ff535bc4ab 100644 (file)
@@ -33,7 +33,7 @@ const updateRecorder = (_event, payload: boolean): void => {
 ipcMain.removeAllListeners('update-recorder');
 ipcMain.on('update-recorder', updateRecorder);
 
-// utility function used by play func.
+// Split Buffer into an array of len-sized Buffers.
 function bufSplit(buf: Buffer, len: number): Array<Buffer> {
     let chunks = [];
     let i = 0;
@@ -75,19 +75,19 @@ export function initAudioIO(): void {
 }
 
 // play audio buffers.
-export function play(input: string): void {
+export function play(input: Buffer): void {
     let i = 0;
-    console.log(Buffer.from(input, encoding));
-    // format buffers into half their size to account for writable highwaterMark.
-    const audio = bufSplit(Buffer.from(input), 8192);
-    console.log(audio);
+
+    const audio = bufSplit(input, 8192);
 
     // call this fuction after last audio chunk has been written.
     const callback = () => {
         // TODO: clear portAudio writable buffer on write end.
     }
+
     write();
-    // iterate through audio array and write buffers to portAudio writable.
+
+    // Iterate through audio array and write buffers to portAudio writable.
     function write() {
         let chunk: Buffer;
         let ok = true;
index bd42b345f1d1b95fa4ae9e799686019a78c64cd3..75f9433141eee842c6e356ee67a53366fd9a7a35 100644 (file)
@@ -32,6 +32,7 @@ let socket: WebSocket;
 let success = false;
 let auth = false;
 
+
 const authSession = async (_event, payload: string | UserCreds | null): Promise<string> => {
     return new Promise((resolve, reject) => {
 
@@ -60,6 +61,17 @@ const authSession = async (_event, payload: string | UserCreds | null): Promise<
     });
 };
 
+// function parseHexString(str: string) { 
+//     var result = [];
+//     while (str.length >= 8) { 
+//         result.push(parseInt(str.substring(0, 8), 16));
+
+//         str = str.substring(8, str.length);
+//     }
+
+//     return result;
+// }
+
 const receiveMessage = (message: string): void => {
 
     while (!auth) {
@@ -67,12 +79,16 @@ const receiveMessage = (message: string): void => {
         return;
     }
 
+    // Parse the message.
     const parsed: RenderMessage = JSON.parse(message);
     console.log('message received', parsed.content.text);
+
+    // If there is audio, play it.
     if (parsed.content.audio) {
-        console.log('audio received');
-        play(parsed.content.audio);
+        const audioBytes = Buffer.from(parsed.content.audio, 'hex');
+        play(audioBytes);
     }
+
     backgroundMitt.emit('ipc-renderer', {
         endpoint: 'render-message',
         message: parsed
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e623548cd614bf1ec77b3f7767e114add70bed7c 100644 (file)
@@ -0,0 +1,19 @@
+<template>
+  Input Item Content
+</template>
+
+<script lang="ts">
+
+import { defineComponent, onMounted, ref, onUnmounted } from "vue";
+import { calcSideProximity, calcPosition } from "./helpers"
+
+export default defineComponent({
+
+
+});
+
+</script>
+
+<style lang="scss" scoped>
+
+</style>
\ No newline at end of file