VoiceRecognition.cs
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**********************
********LAVID**********
***VLibras Project*****
*------------------------------------------------------------------------
*Description:
*
*This class needs an android plugin to call Google Speech API
*Before recognition, it verifies if there is internect connection.
*If there is no connection, the application doesn't run and shows an error message.
*
*---------------------------------------------------------------------------
*Plugin directory:
* - Assets/Plugins/Android
*References:
* - http://docs.unity3d.com/ScriptReference/AndroidJavaClass.html
* - https://msdn.microsoft.com/pt-br/library/system.net.webclient(v=vs.110).aspx
*
*------------------------------------------------------------------------
*Author: Claudiomar Araujo
*claudiomar.araujo@lavid.ufpb.br
***********************/
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class VoiceRecognition {
AndroidJavaClass unity;
AndroidJavaObject currentActivity;
string voiceText = "";
public VoiceRecognition()
{
#if !UNITY_EDITOR
unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
#endif
}
// Calls Google Speech from plugin method and returns recognized text
public string callRecognition()
{
#if !UNITY_EDITOR
voiceText = currentActivity.Call<string>("callGoogleSpeech");
#endif
return voiceText;
}
}