This repo provides some minimal scripts to integrate Speechmatics RT SaaS into a Unity project.
These scripts use the websocket interface to send audio and recieve transcripts. The scripts utilise events to broadcast recieved events, which can be listened for by many components in your project.
The websocket implementation used is from the NativeWebsocket package: NWS_github. This can be installed via the unity package manager:
Install via UPM (Unity Package Manager)
- Open Unity
- Open Package Manager Window
- Click Add Package From Git URL
- Enter URL: https://github.com/endel/NativeWebSocket.git
or by manually cloning the repo:
git clone https://github.com/endel/NativeWebSocket
cp -r NativeWebSocket/NativeWebSocket/Assets/WebSocket /path/to/project/AssetsTo use this package, you must have a Speechmatics API key, which can be acquired from: Speechmatics Portal
Apply both the scripts to a game object as shown:
Enter your api key into the editor as shown. When run, the websocket connection will take a few seconds. You can listen to OnConnectionEstablished to see when this is finished. You should get asked for permission to access your microphone. If you set the verbosity to 1, you will be able to see the transcripts in the terminal output.
Speechmatics provides partials (less accurate, subject to change) and final results. These are broadcast to:
- OnTranscriptionReceived
- OnPartialTranscriptionReceived
You can add listeners to your script with:
speechmaticsClient.OnTranscriptionReceived += OnTranscriptionReceived;
speechmaticsClient.OnPartialTranscriptionReceived += OnPartialTranscriptionReceived;
speechmaticsClient.OnConnectionEstablished += OnConnectionEstablished;