Added Support for Multiple Languages

This commit is contained in:
Paoda 2018-09-07 11:01:14 +01:00
parent 9f6adb3a29
commit 36411bb2c5
1 changed files with 71 additions and 72 deletions

View File

@ -1,10 +1,10 @@
import io from 'socket.io-client'; import io from 'socket.io-client';
/** /**
* The Class Responsible for Talking with Polyglot-Node * The Class Responsible for Talking with Polyglot-Node
* @param {string} url - URL of NodeJS Server. * @param {string} url - URL of NodeJS Server.
*/ */
class WebSocket { class WebSocket {
constructor(url) { constructor(url) {
this.io = io(url); this.io = io(url);
@ -23,14 +23,13 @@ class WebSocket {
}) })
this.io.on('connect', (data) => { this.io.on('connect', (data) => {
this.io.emit("join", "Hi There NodeJS!");
console.log("Connected to NodeJS Server"); console.log("Connected to NodeJS Server");
cb(); cb();
}); });
} }
/** /**
* This Class Grabs the Audio from the User. * This Class Grabs the Audio from the User.
* Line 26 needs to be replaced with the global variable for localstream found in Rails TODO: Put line * Line 48 needs to be replaced with the global variable for localstream found in Rails TODO: Put line
* *
* DEPRECAION WARNING. This method makes vital use of createScriptProcessor which will be scrapped at some point * DEPRECAION WARNING. This method makes vital use of createScriptProcessor which will be scrapped at some point
* in the future. TODO: Switch from createScriptProcessor to AudioWorklet (No documentation as of 2018-08-30) * in the future. TODO: Switch from createScriptProcessor to AudioWorklet (No documentation as of 2018-08-30)
@ -38,7 +37,7 @@ class WebSocket {
* @async * @async
*/ */
async grabAudio() { async grabAudio() {
this.io.emit('startRecognition', "en-US"); this.io.emit('startRecognition', "en-US", "fr");
AudioContext = window.AudioContext || window.webkitAudioContext; AudioContext = window.AudioContext || window.webkitAudioContext;
const ctx = new AudioContext(); const ctx = new AudioContext();
@ -69,7 +68,7 @@ class WebSocket {
function convertF32ToI16(buffer) { function convertF32ToI16(buffer) {
let l = buffer.length; let l = buffer.length;
let buf = new Int16Array(l/3); let buf = new Int16Array(l / 3);
while (l--) { while (l--) {
if (l % 3 == 0) { if (l % 3 == 0) {
@ -79,6 +78,6 @@ class WebSocket {
return buf.buffer; return buf.buffer;
} }
} }
} }
const ws = new WebSocket("http://localhost:1337"); const ws = new WebSocket("http://localhost:1337");