Skip to content

Instantly share code, notes, and snippets.



Last active May 9, 2018
What would you like to do?
Speech to Text for Processing using WebSockets and Google Chrome.
Simple WebSocketServer example that can receive voice transcripts from Chrome
Requires WebSockets Library:
import websockets.*;
WebsocketServer socket;
void setup() {
socket = new WebsocketServer(this, 1337, "/p5websocket");
void draw() {
void webSocketServerEvent(String msg){
<script type="text/javascript">
// We need to check if the browser supports WebSockets
if ("WebSocket" in window) {
// Before we can connect to the WebSocket, we need to start it in Processing.
var ws = new WebSocket("ws://localhost:1337/p5websocket");
} else {
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
// Now we can start the speech recognition
// Supported only in Chrome
// Once started, you need to allow Chrome to use the microphone
var recognition = new webkitSpeechRecognition();
// Be default, Chrome will only return a single result.
// By enabling "continuous", Chrome will keep the microphone active.
recognition.continuous = true;
recognition.onresult = function(event) {
// Get the current result from the results object
var transcript = event.results[event.results.length-1][0].transcript;
// Send the result string via WebSocket to the running Processing Sketch
// Start the recognition
// Restart the recognition on timeout
recognition.onend = function(){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment