Talking Chess: Adding Offline, Cross-Platform Voice Controls to Chess in .NET Core
By: Ian Lavery
Tags: Cross Platform, Dotnet, Voice Assistant, Speech Recognition, Chess

For years, developers looking to add speech recognition to applications have faced a daunting task. They either open their application up to big speech recognition providers in the cloud or, they spend weeks integrating a subpar offline approach. At Picovoice, we are shifting this paradigm. Our goal at Picovoice is to give developers the power to design, build and integrate offline voice interfaces in as little time as possible.

Since developer experience is paramount to us, it’s important that we frequently put ourselves in the shoes of a developer using our SDKs. To see if our developer experience is as seamless as we claim, I recently decided to use our new .NET SDK to build a voice interface for a game. A lot of people are talking chess right now thanks to Netflix’s new hit series Queen’s Gambit, so I thought it would be a good idea to make chess you can talk to!

To accurately simulate this experience, I had to impose some constraints:

Use .NET Core, but keep it cross-platform (should be able to play on Windows, Linux and Mac)

Use Picovoice NuGet package

Use Picovoice Console to design my voice commands

Invest no more than a couple of hours of my time

From these constraints, you can probably infer that I didn’t want to build a chess game; no, I just wanted to integrate a voice interface for one. Luckily, I found a great open-source project on Github called ChessCore that implemented a chess engine in .NET Core, was cross-platform and had a text-based interface. Perfect — time to get to work!

Out With the Old, In With the New

Conveniently, ChessCore has kept the chess-playing engine completely separate from the interface. This allowed me to remove the text-based interface and replace it with an entirely voice-controlled one.

We don’t want to throw out everything from this interface, however. First I want to extract the functions that execute/validate player moves, translate moves to the coordinate system used by the engine and draw the chessboard to the console. After extracting all of the useful items from the original Program.cs, we have something that looks like this:

Now we need to fill in RunGame() with our new voice interface — but first, we need to design our voice experience in the Picovoice Console.

Designing a Voice UI with the Picovoice Console

First, we’ll want a wake word for our game — something that is always listened for and serves to open the gate to our voice command interface. A wake word is a great way of communicating to a voice command interface that we want it to start listening for commands from incoming audio. Picovoice offers a highly-accurate wake word engine called Porcupine that accepts custom wake words designed and built in the Picovoice Console.

To make a custom wake word, we can go to the Porcupine section of the Picovoice Console and simply type in a phrase we want our game to respond to. For this game, I’ll use the wake word “Pico Chess”. You can then select what platform you want the wake word model to run on. To keep it cross-platform we’ll make one for Windows, macOS and Linux. After testing it with the microphone widget to ensure it responds well, I’ll click the Train Wake Word button to start training my custom wake word.