]> Repos - mime-chat/commitdiff
remove google cloud client from background
authorriqo <hernandeze2@xavier.edu>
Wed, 3 Feb 2021 15:27:18 +0000 (09:27 -0600)
committerriqo <hernandeze2@xavier.edu>
Wed, 3 Feb 2021 15:27:18 +0000 (09:27 -0600)
src/background.ts
src/main.ts
testAudio.js

index b8f649dfaf09efc3353efa15e902b3d3c8b073a0..de64c268ce750f7225091250974f488bae200f8b 100644 (file)
@@ -8,39 +8,6 @@ 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 = {
@@ -54,15 +21,9 @@ const audioOptions = {
 const ai = new portAudio.AudioIO({
   inOptions: audioOptions
 });
-ai.pipe(recognizeStream);
+//ai.pipe();
 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);
-
 // 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;
@@ -125,19 +86,9 @@ function createWindow() {
 
     ipcMain.on('update-recorder', (Event: any, record: boolean) => {
      if (record) {
-       // ai.start();
+       // start recording
      } else {
-       // ai.quit();
-
-       // const audio = {
-       //   content: fs.readFileSync(filename).toString('base64'), 
-       // }
-       // const message = {
-       //   text: "",
-       //   audio: audioData
-       // }
-       // ws.send(JSON.stringify(message))
-       // audioData = "";
+       // stop recording
      }
     })
   })
index bc2fa9d5e7779bc93c8e6328de6d9c808f8d653d..531bb906a096c75b882cc0190647253b63a7b359 100644 (file)
@@ -1,7 +1,6 @@
 import { createApp } from "vue";
 import App from "./App.vue";
 import router from "./router";
-import store from "./store";
 
 // animation library
 import anime from "animejs";
@@ -11,7 +10,6 @@ import mitt from "mitt";
 const emitter = mitt();
 
 createApp(App)
-  .use(store)
   .use(router)
   .provide("animejs", anime)
   .provide("mitt", emitter)
index 6a92222b6dc4515ecaf7e7afcf5700d10de93e3a..3312d27b3890a8a332f14e4673617f4c641530e7 100644 (file)
@@ -1,71 +1,40 @@
 const fs = require('fs');
-// const portAudio = require('naudiodon');
-// Imports the Google Cloud client library
 const speech = require('@google-cloud/speech');
 const portAudio = require('naudiodon');
-
-// 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');
 const WebSocket = require("ws")
-// Start piping data and start streaming
 const {Writable} = require('stream');
+
+// Creates a client
+const client = new speech.SpeechClient();
+
+// connect to test server
 const ws = new WebSocket("ws://localhost:8080");
-//const duplex = WebSocket.createWebSocketStream(ws, { encoding: 'binary' });
+
+// google cloud speech to text settings
+const encoding = 'LINEAR16';
+const sampleRateHertz = 44100;
+const languageCode = 'en-US';
 
 const audioChunks = [];
+
 const audioInputStreamTransform = new Writable({
   write(chunk, encoding, next) {
-    console.log(chunk)
-    // ws send chunk
-    // audioChunks.push(chunk);
-    // ws.send(chunk)
+    console.log(chunk);
+    audioChunks.push(chunk);
     next();
   },
 
   final() {
-    console.log(audioChunks)
-    // ws.send("stop")
-    // stop ws transer
+    console.log(audioChunks);
   },
 });
 
-
-// Creates a client
-const client = new speech.SpeechClient();
-
-/**
- * TODO(developer): Uncomment the following lines before running the sample.
- */
-const filename = './rawAudio.wav';
-const encoding = 'LINEAR16';
-const sampleRateHertz = 44100;
-const languageCode = 'en-US';
-
 const config = {
   encoding: encoding,
   sampleRateHertz: sampleRateHertz,
   languageCode: languageCode,
 };
-const audio = {
-  content: fs.readFileSync(filename).toString('base64'),
-};
-
-// const request = {
-//   config: config,
-//   audio: audio,
-// };
-
-// Detects speech in the audio file
-async function test() {
-  const [response] = await client.recognize(request);
-  const transcription = response.results
-    .map(result => result.alternatives[0].transcript)
-    .join('\n');
-  console.log('Transcription: ', transcription);
-}
-
-// test();
 
 const request = {
   config,
@@ -75,7 +44,7 @@ const request = {
 const speechCallback = (data) => {
   console.log(
       `Transcription: ${data.results[0].alternatives[0].transcript}`
-    )
+    );
 }
 
 const recognizeStream = client
@@ -90,7 +59,7 @@ const recognizeStream = client
 .on('data', speechCallback);
 
 // Create an instance of AudioIO with inOptions (defaults are as below), which will return a ReadableStream
-const audioOptions = {
+const recorderOptions = {
   channelCount: 1,
   sampleFormat: portAudio.sampleFormat16Bit,
   sampleRate: 16000,
@@ -98,13 +67,16 @@ const audioOptions = {
   closeOnError: false // Close the stream if an audio error is detected, if set false then just log the error
 }
 
-const audioData = [];
 const ai = new portAudio.AudioIO({
-  inOptions: audioOptions
+  inOptions: recorderOptions
 });
+
+// manipulate individual chunks as they're available
+// const audioData = [];
 // ai.on('data', (d) => {
 //   audioData.push(d.toString('binary'))
 // })
+
 ai.pipe(audioInputStreamTransform)
 ai.start();
 setTimeout(() => {