*EDIT 7/15/2019* I’m updating this post with my latest code and to remove the dependency on UniExtensions

I’ve made a wrapper around the Windows-only Microsoft Speech API for use in Unity. The Microsoft Speech API is a Windows COM capability that first appeared in windows Vista. It is an easy way to get text to speech in a windows application.

This post will go through the steps of making the C++ DLL and the C# behavior for Unity. If you don’t care about the “how” and just want to use the plugin skip to the end for the download and usage instructions.

The goal of my wrapper is to startup the text-to-speech engine when the game loads, and provide a function to speak a string of text. I’ll need this to run in a thread so that it doesn’t disrupt the main Unity thread.

Native C++

The first step is to write the C++ code that will initialize COM, manage a speech queue and call the Speech API.

Declare functions

I’m going to export three functions in the C++ DLL. These functions will be available to the C# code.