Skip to content

Instantly share code, notes, and snippets.

@seatedro
Last active August 26, 2022 13:57
Show Gist options
  • Save seatedro/40f90b2b2f90bb3a5d67fa8f114f92f5 to your computer and use it in GitHub Desktop.
Save seatedro/40f90b2b2f90bb3a5d67fa8f114f92f5 to your computer and use it in GitHub Desktop.
Transcription Server 2
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.
socket.on(
"startGoogleCloudStream",
(request: google.cloud.speech.v1.IStreamingRecognitionConfig) => {
// Very long type, but alas that's what Google decided to use.
speechToTextUtils._request = request;
console.log("Starting Google Cloud Transcription");
speechToTextUtils.startRecognitionStream();
}
);
// Receive audio data from front-end
socket.on("binaryAudioData", (data: DataView) => {
speechToTextUtils.receiveData(data);
});
// End the audio stream
socket.on("endGoogleCloudStream", () => {
speechToTextUtils.stopRecognitionStream();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment