3. 続いてシーンを保存します。[Add Open Scenes]をクリックして、[新しいフォルダー]を選択しScenesと名前をつけた後、そのフォルダー内に名前をMR_LuisSceneとして[保存]します。
4.シーン作成
シーン内にオブジェクトを配置していきたいと思います。
1. 土台の配置
[Hierarchy]->[Create]->[3D Object]->[Plane]で土台を作り、[Inspector]->[Transform]を編集していきます。
—————————————–
Position | X : 0 | Y : -1 | Z : 0
—————————————–
2. 球の配置
[Hierarchy]->[Create]->[3D Object]->[Sphere]で球を作り、[Inspector]->[Transform]を編集していきます。
—————————————–
Position | X : 2 | Y : 1 | Z : 2
—————————————–
3. シリンダーの配置
[Hierarchy]->[Create]->[3D Object]->[Cylinder]でシリンダーを作り、[Inspector]->[Transform]を編集していきます。
—————————————–
Position | X : -2 | Y : 1 | Z : 2
—————————————–
4. 正方形の配置
[Hierarchy]->[Create]->[3D Object]->[Cube]で正方形を作り、[Inspector]->[Transform]を編集していきます。
———————————————-
Position | X : 0 | Y : 1 | Z : 4
———————————————-
Rotation | X : 45 | Y : 45 | Z : 45
———————————————-
5. テキストの配置
a. [Hierarchy]->[Create]->[3D Object]->[Text]でテキストを作り、名前をDictationTextとします。[Inspector]->[Transform]を編集していきます。
———————————————
Position | X : -2 | Y : 6 | Z : 9
———————————————
Scale | X : 0.1 | Y : 0.1 | Z : 0.1
———————————————
・MicrophoneManagerLuis
このクラスはMicrophoneで音声をキャプチャし、そのキャプチャした音声をテキストにするクラスです。聞いた音声を順に文字におこしていきます。今回は簡単のため「change」と聞き取ったらテキストを「The color of the cylinder must be red」として使用することにします。また、しゃべった言葉を直接使う方法については後述します。喋り始めてから一度止まるまでの音声がテキストになります。コードは以下の通りです。
C#
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
54
55
56
57
usingSystem.Collections;
usingSystem.Collections.Generic;
usingUnityEngine;
usingUnityEngine.Windows.Speech;
publicclassMicrophoneManagerLuis:MonoBehaviour
{
publicstaticMicrophoneManagerLuis instance;//help to access instance of this object
privateintfrequency=44100;//recording frequency of mic
privateAudioSource audioSource;//AudioSource component, provides access to mic
privateDictationRecognizer dictationRecognizer;//Component converting speech to text
publicTextMesh dictationText;//a UI object used to debug dictation result
privatevoidAwake()
{
// allows this class instance to behave like a singleton
instance=this;
}
// Use this for initialization
voidStart()
{
if(Microphone.devices.Length>0)
{
// Once the scene starts, begin to capture the audio
audioSource=GetComponent<AudioSource>();
Debug.Log("Mic Detected");
StartCapturingAudio();
}
}
/// <summary>
/// Start microphone capture, by providing the microphone as a continual audio source (looping),
/// then initialise the DictationRecognizer, which will capture spoken words
・LuisManager
このクラスのやることはMicrophoneManagerLuisクラスからテキストを受け取り、Azure Language Understanding APIにテキストを送ることです。ここで2.準備(2)で取得したEndpointを使用します。–Insert your Endpoint–にEndpointを挿入してください。コードは以下の通りです。
C#
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
usingSystem;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.IO;
usingUnityEngine;
usingUnityEngine.Networking;
publicclassLuisManager:MonoBehaviour
{
[System.Serializable]//this class represents the LUIS response
publicclassAnalysedQuery
{
publicTopScoringIntentData topScoringIntent;
publicEntityData[]entities;
publicstringquery;
}
// This class contains the Intent LUIS determines
// to be the most likely
[System.Serializable]
publicclassTopScoringIntentData
{
publicstringintent;
publicfloatscore;
}
// This class contains data for an Entity
[System.Serializable]
publicclassEntityData
{
publicstringentity;
publicstringtype;
publicintstartIndex;
publicintendIndex;
publicfloatscore;
}
publicstaticLuisManager instance;
//Substitute the value of luis Endpoint with your own End Point
stringluisEndpoint=" --Insert your Endpoint --";
privatevoidAwake()
{
// allows this class instance to behave like a singleton