Google Cloud Speech Recognition
Hierarchy
1) Interfaces:
1.1) ILowLevelSpeechRecognition
* Method: Recognize
* Method: StartRecord
* Method: StopRecord
* Event: SpeechRecognizedSuccessEvent
* Event: SpeechRecognizedFailedEvent
2) Classes:
2.1) SpeechRecognitionModule – implements ILowLevelSpeechRecognition
2.2) RuntimeSpeechDetection
2.3) RecognitionAudio
2.4) RecognitionConfig
2.5) RecognitionRequest
2.6) RecognitionResponse
2.7) SpeechContext
2.8) PCMWrapper
2.9) MicrophoneWorker
2.10) Enumerators
2.10.1) Enum: Language
3) 3rd Libraries:
3.1) Newtonsoft.Json (JsonDotNet)
How to use
First of All you need to add SpeechRecognitionModule prefab from FrostweepGames->GoogleCloudSpeechRecognition->Prefabs folder to your working scene.
Then you need to set your own API key of Google Cloud Speech Recognition into Custom Api Key field.
If you don’t have API Key, you can get it from https://cloud.google.com/speech/, https://cloud.google.com/speech/docs/common/auth#restrictions
Also you can change default Language on what you need, Enable Runtime Speech Detection[0],
Set runtime speech detection treshold, Enable profanity filter, Set count of alternatives for speech recognition result[1],
Set speech context phrases[2].
Record Length field uses for how long we record speech. Is Loop Recording field sets the loop of recording every Record Length seconds.
Then we need to create script with name Example and write base logic:
Where SpeechRecognizedSuccessEventHandler is the event handler of SpeechRecognizedSuccessEvent
and SpeechRecognizedFailedEventHandler is the event handler of SpeechRecognizedFailedEvent.
SpeechRecoginezedSuccessEvent will fire when speech recognition will returned response.
This event has a RecognitionResponse param type.
SpeechRecoginezedFailedEvent will fire when speech recognition failed. This event has a string param type.
You can handle response of Speech Recognition in SpeechRecognizedSuccessEventHandler
To get result of recognition you can use “RecognitionResponse->results->alternatives.transcript” path.
Where RecognitionResponse is instance of RecognitionResponse object.
For the start recording you can call this method:
For the stop recording you can call this method:
the start runtime speech detection and recording you can call this method:
For the stop runtime speech detection and recording you can call this method:
Example scene included to project:
FrostweepGames-> GoogleCloudSpeechRecognition->Examples
[0] – Enable runtime speech detection and disable solitary speech recording
[1] – Count of alternative words range: 1 - 30
[2] – An array of phrases in context
Note
• Example script included in unitypackage!
• Working with il2cpp and mono
• Supported all platforms*
• Plugin Support Unity3D 4 or above
* - Plugin doesn't support WebPlayer.
- On WebGL Unity engine doesn't support "Microphone" the class
Version Updates
• 2.0
- UPDATED Speech Recognition API to the latest Google Cloud Speech API
- implemented new features
- implemented speech detection treshold
- changed namespaces
- fixed bugs
• 1.1
- Changed Code Namespace with FrostweepGames.SpeechRecognition on FrostweepGames.SpeechRecognition.Google
- Implemented Runtime Speech Detection Utility