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 = {
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;
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({
--- /dev/null
+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