]> Repos - mime-chat/commitdiff
manual remove audioInput after write
authorEnrique Hernandez <hernandeze2@xavier.edu>
Tue, 2 Mar 2021 14:42:30 +0000 (08:42 -0600)
committerEnrique Hernandez <hernandeze2@xavier.edu>
Tue, 2 Mar 2021 14:42:30 +0000 (08:42 -0600)
src/background/audio.ts
tests/audio.js

index 50c052f37760c897ba1d82a9ae7090d85f1e6857..4739b0c28960af037dc4f69f33ceeba5ad7a8d4e 100644 (file)
@@ -7,7 +7,7 @@ const portAudio = require('naudiodon');
 
 let ai: typeof portAudio.AudioIO;
 let ao: typeof portAudio.AudioIO;
-let audioInput: Buffer[] = [];
+const audioInput: Buffer[] = [];
 const encoding = "base64";
 const audioOptions = {
     channelCount: 1,
@@ -57,7 +57,8 @@ export const updateRecorder = (_event, record: boolean): void => {
         // stop mic data flow on space bar key up.
         ai.pause();
         const audio = Buffer.concat(audioInput);
-        sendAudio(audio);
+        play(audioInput);
+        // sendAudio(audio);
         while (audioInput.length) { audioInput.pop(); }
     }
 }
@@ -98,7 +99,7 @@ export const play = (input: Array<Buffer>) => {
 
 // utility function used by play func
 function bufSplit(input: Array<Buffer>): Array<Buffer> {
-    let result: Buffer[] = [];
+    const result: Buffer[] = [];
     input.forEach((b: Buffer) => {
         // split buffer into two.
         result.push(b.slice(0, b.length / 2), b.slice(b.length / 2, b.length));
index c4d645f37157ff4708cb8b7134ae736d3e61b5be..7ffe6d01ede88ff8d7bfeb9d2428b9b55da696eb 100644 (file)
@@ -40,7 +40,7 @@ async function transcribeSpeech (audio) {
   console.log(`Transcription: ${transcription}`);
 }
 
-let audioInput = [];
+const audioInput = [];
 // Create an instance of AudioIO with inOptions (defaults are as below), which will return a ReadableStream
 const ia = new portAudio.AudioIO({
   inOptions: {
@@ -74,7 +74,7 @@ async function processAudio() {
     const buf = Buffer.concat(audioInput);
     play(audioInput);
 
-    while(audioInput.length) { audioInput.pop() };
+    while(audioInput.length) { audioInput.pop() }
 
    transcribeSpeech({
        content: buf
@@ -117,7 +117,7 @@ async function processAudio() {
 
 // utility function used by play func
 function bufSplit(input){
-    let result = [];
+    const result = [];
     input.forEach((b) => {
         // split buffer into two.
         result.push(b.slice(0, b.length / 2), b.slice(b.length / 2, b.length));
@@ -140,5 +140,10 @@ setTimeout(async () => {
 }, 8000);
 
 setTimeout(() => {
+    ia.resume();
+}, 10000)
+
+setTimeout(async () => {
     ia.pause();
-}, 9000)
+    processAudio();
+}, 15000);