This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import csv | |
import re | |
import cv2 | |
import os | |
import glob | |
import xml.etree.ElementTree as ET | |
import io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output_directory = 'exported-models/' | |
# goes through the model is the training/ dir and gets the last one. | |
# you could choose a specfic one instead of the last | |
lst = os.listdir("models/my_mobilenet/") | |
# print(lst) | |
lst = [l for l in lst if 'ckpt-' in l and '.index' not in l] | |
steps=np.array([int(re.findall('\d+', l)[0]) for l in lst]) | |
last_model = lst[steps.argmax()] | |
last_model_path = os.path.join('models/my_mobilenet', last_model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from PIL import Image | |
from google.colab.patches import cv2_imshow | |
def load_image_into_numpy_array(path): | |
"""Load an image from file into a numpy array. | |
Puts image into numpy array to feed into tensorflow graph. | |
Note that by convention we put it into a numpy array with shape | |
(height, width, channels), where channels=3 for RGB. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express, { Express, Request, Response } from "express"; | |
import { createServer } from "https"; | |
const app: Express = express(); | |
const server = createServer( | |
{ | |
key: fs.readFileSync("key.pem"), | |
cert: fs.readFileSync("cert.pem"), | |
}, | |
app | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { google } from "@google-cloud/speech/build/protos/protos"; | |
import { Server, Socket } from "socket.io"; | |
import speechToTextUtils from "./speechToTextUtils"; | |
io.on("connection", (socket: Socket) => { | |
console.log("Socket Connection: ", socket.connected); | |
console.log("Socket Id: ", socket.id); | |
speechToTextUtils._socket = socket; | |
// Define socket eventListeners. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import speech, { SpeechClient } from '@google-cloud/speech'; | |
import { google } from '@google-cloud/speech/build/protos/protos'; | |
import * as pumpify from 'pumpify'; | |
import chalk from 'chalk'; | |
import { Socket } from 'socket.io'; | |
let speechClient: SpeechClient | null = null; | |
class SpeechToTextUtils { | |
recognizeStream!: pumpify | null; | |
resultEndTime = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Receives streaming data and writes it to the recognizeStream for transcription | |
* | |
* @param {Buffer} data A section of audio data | |
*/ | |
receiveData(data: DataView) { | |
if ( | |
this.newStream && | |
this.lastAudioInput.length !== 0 && | |
this.recognizeStream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
restartStream() { | |
if (this.recognizeStream) { | |
this.recognizeStream.end(); | |
this.recognizeStream.removeAllListeners(); | |
this.recognizeStream = null; | |
} | |
if (this.resultEndTime > 0) { | |
this.finalRequestEndTime = this.isFinalEndTime; | |
} | |
this.resultEndTime = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { io, Socket } from 'socket.io-client'; | |
import {AudioStreamer} from 'src/app/app.service'; | |
constructor(private audioStreamer: AudioStreamer) { | |
this.liveTranscription = ''; | |
this.socket = io('https://localhost:3000'); | |
this.socket.on('connect', () => { | |
console.log('Socket Connection: ', this.socket?.connected); | |
}) | |
this.audioStreamer._socket = this.socket; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { Socket } from 'socket.io-client'; | |
// Stream Audio | |
let bufferSize = 2048, | |
AudioContext; | |
//audioStream constraints | |
const constraints = { | |
audio: true, |
OlderNewer