electron audio module

This commit is contained in:
Andrew Gundersen 2021-05-27 14:02:36 -05:00
commit eddbe140df
13 changed files with 2225 additions and 1908 deletions

View file

@ -26,7 +26,7 @@
"electron-is-dev": "^2.0.0", "electron-is-dev": "^2.0.0",
"electron-updater": "^4.3.8", "electron-updater": "^4.3.8",
"mitt": "^2.1.0", "mitt": "^2.1.0",
"naudiodon": "^2.3.2", "naudiodon": "^2.3.5",
"node-record-lpcm16": "^1.0.1", "node-record-lpcm16": "^1.0.1",
"update-electron-app": "^2.0.1", "update-electron-app": "^2.0.1",
"uuid": "^8.3.2", "uuid": "^8.3.2",
@ -57,7 +57,7 @@
"eslint": "^6.7.2", "eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0-0", "eslint-plugin-vue": "^7.0.0-0",
"lint-staged": "^9.5.0", "lint-staged": "^9.5.0",
"node-sass": "^4.12.0", "node-sass": "4",
"optimize-wasm-webpack-plugin": "^1.0.12", "optimize-wasm-webpack-plugin": "^1.0.12",
"sass-loader": "^8.0.2", "sass-loader": "^8.0.2",
"spectron": "11.0.0", "spectron": "11.0.0",

View file

@ -6,7 +6,7 @@ export default function initAudioIO () {
console.log('[AUDIO]initializing audio'); console.log('[AUDIO]initializing audio');
// initialize the audio interface // initialize the audio interface
const { const {
read, read,
stopRead, stopRead,
write, write,

View file

@ -43,13 +43,13 @@ async function main(dev: boolean) {
console.log("MAIN:Initializing Electron App.") console.log("MAIN:Initializing Electron App.")
// Must wait til window is created. // Must wait til window is created.
await createWindow(); // await createWindow();
// Begin audio stream. // Begin audio stream.
initAudioIO(); initAudioIO();
// Instantiate socket session with crimata-platorm. // Instantiate socket session with crimata-platorm.
initSession(dev); // initSession(dev);
} }

View file

@ -96,7 +96,7 @@ export default function useTextInputController(elementX: Ref) {
emitter.emit("self-message", message); emitter.emit("self-message", message);
// Send it to the backend for processing. // Send it to the backend for processing.
const clientM = clientMessage(textInput.value, false, message.uid); const clientM = clientMessage(textInput.value, null, message.uid);
post('client-message', clientM); post('client-message', clientM);
clearInput() clearInput()

View file

@ -29,9 +29,9 @@ import draggify from "@/modules/draggify";
import TextInput from "@/components/textInput.vue"; import TextInput from "@/components/textInput.vue";
import useTextInputController from import useTextInputController from
"@/components/controllers/textCtrl"; "@/components/controllers/text-control";
import useAudioInputController from import useAudioInputController from
"@/components/controllers/audioCtrl"; "@/components/controllers/audio-control";
export default defineComponent({ export default defineComponent({
name: "InputItem", name: "InputItem",

View file

@ -2,6 +2,8 @@ const portAudio = require('naudiodon');
const stream = require('stream'); const stream = require('stream');
const fs = require('fs'); const fs = require('fs');
import { AudioData } from "@/types";
// split Buffer into an array of len-sized Buffers // split Buffer into an array of len-sized Buffers
const bufSplit = (buf: Buffer, len: number) => { const bufSplit = (buf: Buffer, len: number) => {
@ -34,6 +36,8 @@ export default function electronAudio () {
let record = false; let record = false;
let readAudio = ''; let readAudio = '';
console.log(portAudio.getHostAPIs());
// get info for given host api // get info for given host api
const getHostInfo = (id: number) => { const getHostInfo = (id: number) => {
return portAudio.getHostAPIs().HostAPIs.filter((host: any) => return portAudio.getHostAPIs().HostAPIs.filter((host: any) =>
@ -48,6 +52,7 @@ export default function electronAudio () {
// constructor to start audio streams // constructor to start audio streams
const setup = () => { const setup = () => {
console.log("Checking audio devices.");
currentHost = portAudio.getHostAPIs().defaultHostAPI; currentHost = portAudio.getHostAPIs().defaultHostAPI;
const hostInfo = getHostInfo(currentHost); const hostInfo = getHostInfo(currentHost);
@ -84,6 +89,7 @@ export default function electronAudio () {
.setEncoding("hex") .setEncoding("hex")
.on('error', () => console.log("input stream error")) .on('error', () => console.log("input stream error"))
.on('data', (chunk: Buffer) => { .on('data', (chunk: Buffer) => {
console.log("data")
if (record) readAudio += chunk.toString(); if (record) readAudio += chunk.toString();
}); });
@ -114,10 +120,18 @@ export default function electronAudio () {
}; };
// remove pipe and return audio contents // remove pipe and return audio contents
const stopRead = () => { const stopRead = (): AudioData => {
const audio = readAudio; const deviceInfo = getDeviceInfo(currentInputDevice);
const audio: AudioData = {
hex: readAudio,
channels: deviceInfo.maxInputChannels,
fs: deviceInfo.defaultSampleRate
}
record = false; record = false;
readAudio = ''; readAudio = '';
return audio; return audio;
}; };

View file

@ -3,7 +3,8 @@ import {
ClientMessage, ClientMessage,
ClientRequest, ClientRequest,
AuthRequest, AuthRequest,
LogoutRequest LogoutRequest,
AudioData
} from "@/types"; } from "@/types";
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
@ -30,7 +31,7 @@ export const renderMessage = (text: boolean | string, audio: boolean | string, c
} }
) )
export const clientMessage = (text: string, audio: string | boolean, uid: string): ClientMessage => ( export const clientMessage = (text: string, audio: AudioData | null, uid: string): ClientMessage => (
{ {
audio, audio,
text, text,

View file

@ -12,9 +12,15 @@ export interface RenderMessage {
newMessage: boolean; newMessage: boolean;
} }
export interface AudioData {
hex: string;
channels: number;
fs: number;
}
export interface ClientMessage { export interface ClientMessage {
text: string; text: string;
audio: boolean | string; audio: AudioData | null;
uid: string; uid: string;
} }

4068
yarn.lock

File diff suppressed because it is too large Load diff