]> Repos - mime-chat/commitdiff
add audio test
authorriqo <hernandeze2@xavier.edu>
Sat, 30 Jan 2021 22:05:59 +0000 (16:05 -0600)
committerriqo <hernandeze2@xavier.edu>
Sat, 30 Jan 2021 22:05:59 +0000 (16:05 -0600)
rawAudio.raw [deleted file]
rawAudio.wav [new file with mode: 0644]
src/background.ts
testAudio.js [new file with mode: 0644]

diff --git a/rawAudio.raw b/rawAudio.raw
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/rawAudio.wav b/rawAudio.wav
new file mode 100644 (file)
index 0000000..5582bc0
Binary files /dev/null and b/rawAudio.wav differ
index 56d341918d5db16ce2ddaa1ee37aac484514d573..71e7d6873f3e8947a258491664fe8ae76ecedfcd 100644 (file)
@@ -6,8 +6,9 @@ import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
 const isDevelopment = process.env.NODE_ENV !== "production";
 import * as path from "path";
 const fs = require('fs');
-
+import WebSocket from "ws";
 const portAudio = require('naudiodon');
+console.log(portAudio.getDevices());
 
 // Create an instance of AudioIO with inOptions (defaults are as below), which will return a ReadableStream
 const audioOptions = {
@@ -18,12 +19,20 @@ const audioOptions = {
   closeOnError: true // Close the stream if an audio error is detected, if set false then just log the error
 }
 
+// Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream
+const ao = new portAudio.AudioIO({
+  outOptions: audioOptions 
+});
+
 let ai = new portAudio.AudioIO({
   inOptions: audioOptions
 });
 
-import WebSocket from "ws";
+const filename = "rawAudio.wav";
 
+// Create a write stream to write out to a raw audio file
+const writeStream = fs.createWriteStream(filename);
+ai.pipe(writeStream);
 // Keep a global reference of the window object, if you don't, the window will
 // be closed automatically when the JavaScript object is garbage collected.
 let win: BrowserWindow | null;
@@ -88,15 +97,19 @@ function createWindow() {
     ipcMain.on('update-recorder', (Event: any, record: boolean) => {
      if (record) {
        ai.start();
-       ai.on('data', (buf: Buffer) => {
-          const base64Data = buf.toString('base64');
-          audioData += base64Data;
-       }); 
+       // ai.on('data', (buf: Buffer) => {
+       //    const base64Data = buf.toString('base64');
+       //    audioData += base64Data;
+       // }); 
      } else {
        ai.quit();
+
+       const audio = {
+         content: fs.readFileSync(filename).toString('base64'), 
+       }
        const message = {
          text: "",
-         audio: audioData
+         audio
        }
        ws.send(JSON.stringify(message))
        ai =  new portAudio.AudioIO({
diff --git a/testAudio.js b/testAudio.js
new file mode 100644 (file)
index 0000000..dd6b6a5
--- /dev/null
@@ -0,0 +1,21 @@
+const fs = require('fs');
+const portAudio = require('naudiodon');
+
+// Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream
+const ao = new portAudio.AudioIO({
+  outOptions: {
+    channelCount: 2,
+    sampleFormat: portAudio.SampleFormat16Bit,
+    sampleRate: 48000,
+    deviceId: -1, // Use -1 or omit the deviceId to select the default device
+    closeOnError: true // Close the stream if an audio error is detected, if set false then just log the error
+  }
+});
+
+// Create a stream to pipe into the AudioOutput
+// Note that this does not strip the WAV header so a click will be heard at the beginning
+const rs = fs.createReadStream('rawAudio.wav');
+
+// Start piping data and start streaming
+rs.pipe(ao);
+ao.start();
\ No newline at end of file