A rock-paper-scissors app with gesture detection and voice
Tags: machinelearning, javascript, serverless, azure
Published: 2020-07-09 13:16:06

_By [David Smith](https://twitter.com/revodavid) and [Em Lazer-Walker](https://twitter.com/lazerwalker), Cloud Advocates at Microsoft_

In this blog post, we’ll show you how to build a web application that will access your camera and say something whenever you make a specific gesture with your hand. This is a simplified version of the [Rock, Paper, Scissors, Lizard, Spock](https://docs.microsoft.com/samples/microsoft/rockpaperscissorslizardspock/azure-rock-paper-scissors/?WT.mc_id=devto-blog-davidsmi) application, and you can [try out the app here](https://victorious-coast-06aa4f30f.azurestaticapps.net/) or deploy it yourself with the instructions below. After you launch the app using a desktop browser, click Start and allow access to your camera, and then make one of the hand gestures from the game created by [Sam Kass and Karen Bryla](http://www.samkass.com/theories/RPSSL.html). Make sure your volume is turned up, and when the application sees a valid gesture, it will speak to you as it is recognized.  
 
[![The app in action](https://dev-to-uploads.s3.amazonaws.com/i/imf5egdzp7s0060f8d4m.png)](https://victorious-coast-06aa4f30f.azurestaticapps.net)

You can customize and run this application yourself by [visiting this GitHub repository](https://github.com/lazerwalker/neural-tts-sample) and following the directions shown. All you need is an [Azure subscription](https://azure.com/free/?WT.mc_id=devto-blog-emwalker), and it uses free services so it won’t cost you anything to try it out. 

Let’s dive into the various components of the application: 

**Speech**. The speech generated when the application detects a valid gesture is generated on demand with [Cognitive Services Neural Text to Speech](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/text-to-speech?WT.mc_id=devto-blog-emwalker). Neural TTS can synthesize a humanlike voice in a variety of languages (with [15 more just added](https://aka.ms/NTTS-new-voices-blog)!) and [speaking styles](https://docs.microsoft.com/azure/cognitive-services/speech-service/speech-synthesis-markup?tabs=csharp&WT.mc_id=devto-blog-emwalker#adjust-speaking-styles). 

**Vision**. The hand gesture detection is driven by [Custom Vision](https://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/home?WT.mc_id=devto-blog-emwalker) in Azure Cognitive Services. It’s based on the same vision model used by the [Rock, Paper, Scissors, Lizard, Spock](https://docs.microsoft.com/samples/microsoft/rockpaperscissorslizardspock/azure-rock-paper-scissors/?WT.mc_id=devto-blog-davidsmi) application, but running locally in the browser. No camera images are sent to the server.  

**Web Application**. The application is built with [Azure Static Web Apps](https://docs.microsoft.com/azure/static-web-apps/overview?WT.mc_id=devto-blog-emwalker), which means you can create your own website with a version of the application in just minutes – and for free! 
 
## Customizing the application 
Because we’ve provided all of the code behind the application, it’s easy to customize and see the differences for yourself. As soon as you check in changes to your forked GitHub repository, Static Web Apps will automatically rebuild and deploy the application with your changes. Here are some things to try, and you can find [detailed instructions in the repository](https://github.com/revodavid/machine-learning-rps/blob/main/CUSTOMIZATION.md).
 
**Customize the speech**. All of the speech generated by the application is defined using the SSML standard, which you can easily customize simply by modifying the text in a JavaScript object.  Here are some things you can try: 

* Change the words spoken for each hand signal by modifying the text. 
* Try changing the default voice or language by configuring the default. 
* Try a different speaking style, like “newscast” or “empathetic” with SSML. 

**Customize what’s recognized by the camera**. The GitHub repository includes only the exported rock-paper-scissors Custom Vision model, but not the source data used to train the model. You train your own vision model with Custom Vision, [export it for TensorFlow.js](https://docs.microsoft.com/azure/cognitive-services/custom-vision-service/export-your-model?WT.mc_id=devto-blog-emwalker), and replace the provided model.  

## Going Deeper 
If you’d like to learn more about the technology used in this app, check out these Microsoft Learn modules on [Static Web Apps](https://docs.microsoft.com/en-us/learn/modules/publish-app-service-static-web-app-api/?WT.mc_id=devto-blog-emwalker), [Custom Vision](https://docs.microsoft.com/en-us/learn/modules/classify-images-with-custom-vision-service/?WT.mc_id=devto-blog-emwalker), and [Text-to-Speech](https://docs.microsoft.com/en-us/learn/modules/synthesize-text-input-speech/?WT.mc_id=devto-blog-emwalker). If you have any feedback about the app itself, please leave an issue in the Github repository, or reach out to either of us ([David](https://twitter.com/revodavid) and [Em](https://twitter.com/lazerwalker)) directly. This was a fun app to make, and we hope you have fun playing with it too!