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

View file

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

View file

@ -43,13 +43,13 @@ async function main(dev: boolean) {
console.log("MAIN:Initializing Electron App.")
// Must wait til window is created.
await createWindow();
// await createWindow();
// Begin audio stream.
initAudioIO();
// 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);
// 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);
clearInput()

View file

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

View file

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

View file

@ -3,7 +3,8 @@ import {
ClientMessage,
ClientRequest,
AuthRequest,
LogoutRequest
LogoutRequest,
AudioData
} from "@/types";
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,
text,

View file

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

4068
yarn.lock

File diff suppressed because it is too large Load diff