cleaning some things up
This commit is contained in:
parent
7ea09b99f0
commit
9bf01c0a33
12 changed files with 48 additions and 694 deletions
|
|
@ -1,67 +1,11 @@
|
|||
"use strict";
|
||||
|
||||
import { app, protocol, BrowserWindow, ipcMain } from "electron";
|
||||
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
||||
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');
|
||||
const speech = require('@google-cloud/speech');
|
||||
|
||||
const client = new speech.SpeechClient();
|
||||
|
||||
const encoding = 'LINEAR16';
|
||||
const sampleRateHertz = 16000;
|
||||
const languageCode = 'en-US';
|
||||
|
||||
const config = {
|
||||
encoding: encoding,
|
||||
sampleRateHertz: sampleRateHertz,
|
||||
languageCode: languageCode,
|
||||
};
|
||||
const request = {
|
||||
config,
|
||||
interimResults: true,
|
||||
};
|
||||
|
||||
const speechCallback = (d: any) => {
|
||||
console.log(d)
|
||||
}
|
||||
|
||||
const recognizeStream = client
|
||||
.streamingRecognize(request)
|
||||
.on('error', err => {
|
||||
if (err.code === 11) {
|
||||
// restartStream();
|
||||
} else {
|
||||
console.error('API request error ' + err);
|
||||
}
|
||||
})
|
||||
.on('data', speechCallback);
|
||||
|
||||
|
||||
// Create an instance of AudioIO with inOptions (defaults are as below), which will return a ReadableStream
|
||||
const audioOptions = {
|
||||
channelCount: 2,
|
||||
sampleFormat: portAudio.sampleFormat16Bit,
|
||||
sampleRate: 16000,
|
||||
deviceId: -1, // Use -1 or omit the deviceId to select the default device
|
||||
closeOnError: false // Close the stream if an audio error is detected, if set false then just log the error
|
||||
}
|
||||
|
||||
const ai = new portAudio.AudioIO({
|
||||
inOptions: audioOptions
|
||||
});
|
||||
ai.pipe(recognizeStream);
|
||||
ai.start();
|
||||
|
||||
|
||||
// const filename = "rawAudio.wav";
|
||||
// Create a write stream to write out to a raw audio file
|
||||
// const writeStream = fs.createWriteStream(filename, { encoding: 'binary'});
|
||||
// ai.pipe(writeStream);
|
||||
const isDevelopment = process.env.NODE_ENV !== "production";
|
||||
|
||||
// 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.
|
||||
|
|
@ -73,18 +17,28 @@ protocol.registerSchemesAsPrivileged([
|
|||
]);
|
||||
|
||||
function createWindow() {
|
||||
|
||||
// Create the browser window.
|
||||
win = new BrowserWindow({
|
||||
width: 450,
|
||||
height: 1025,
|
||||
resizable: true,
|
||||
width: 350,
|
||||
height: 520,
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
|
||||
// Postition at launch
|
||||
x: 100,
|
||||
y: 100,
|
||||
|
||||
webPreferences: {
|
||||
// Use pluginOptions.nodeIntegration, leave this alone
|
||||
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
|
||||
nodeIntegration: (process.env
|
||||
.ELECTRON_NODE_INTEGRATION as unknown) as boolean,
|
||||
devTools: false,
|
||||
|
||||
nodeIntegration:
|
||||
(process.env.ELECTRON_NODE_INTEGRATION as unknown) as boolean,
|
||||
|
||||
preload: path.join(__dirname, "preload.js")
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
||||
|
|
@ -98,12 +52,17 @@ function createWindow() {
|
|||
win.loadURL("app://./index.html");
|
||||
}
|
||||
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
|
||||
// Define the websocket
|
||||
const ws = new WebSocket("ws://localhost:8080");
|
||||
|
||||
// Send ID on open.
|
||||
ws.on("open", function open() {
|
||||
// ws.send("hernandeze2@xavier.edu");
|
||||
ws.send("gundersena@crimata.com");
|
||||
});
|
||||
|
||||
ws.on("message", (message: any) => {
|
||||
const parsed = JSON.parse(message);
|
||||
console.log('new message', message)
|
||||
|
|
@ -124,21 +83,7 @@ function createWindow() {
|
|||
})
|
||||
|
||||
ipcMain.on('update-recorder', (Event: any, record: boolean) => {
|
||||
if (record) {
|
||||
// ai.start();
|
||||
} else {
|
||||
// ai.quit();
|
||||
|
||||
// const audio = {
|
||||
// content: fs.readFileSync(filename).toString('base64'),
|
||||
// }
|
||||
// const message = {
|
||||
// text: "",
|
||||
// audio: audioData
|
||||
// }
|
||||
// ws.send(JSON.stringify(message))
|
||||
// audioData = "";
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue