From: riqo Date: Sat, 30 Jan 2021 22:05:59 +0000 (-0600) Subject: add audio test X-Git-Tag: v0.9~116 X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=b1a02d6596d8c4be8a7d53792b48b1e0c274bdaf;p=mime-chat add audio test --- diff --git a/rawAudio.raw b/rawAudio.raw deleted file mode 100644 index e69de29..0000000 diff --git a/rawAudio.wav b/rawAudio.wav new file mode 100644 index 0000000..5582bc0 Binary files /dev/null and b/rawAudio.wav differ diff --git a/src/background.ts b/src/background.ts index 56d3419..71e7d68 100644 --- a/src/background.ts +++ b/src/background.ts @@ -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 index 0000000..dd6b6a5 --- /dev/null +++ b/testAudio.js @@ -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