Last active
August 26, 2022 13:57
-
-
Save seatedro/40f90b2b2f90bb3a5d67fa8f114f92f5 to your computer and use it in GitHub Desktop.
Transcription Server 2
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. | |
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