質問編集履歴

2

中かっこの数が足りていないかったので追記

2018/07/24 09:42

投稿

north
north

スコア8

test CHANGED
File without changes
test CHANGED
@@ -466,6 +466,10 @@
466
466
 
467
467
  }
468
468
 
469
+ }
470
+
471
+ }
472
+
469
473
  ```
470
474
 
471
475
  文字数オーバーになるため関係ないと思われるところは省略しています。

1

コードの追記

2018/07/24 09:42

投稿

north
north

スコア8

test CHANGED
File without changes
test CHANGED
@@ -19,3 +19,455 @@
19
19
 
20
20
 
21
21
  原因、対策をご教示いただけたらと思います。
22
+
23
+
24
+
25
+ ```C#
26
+
27
+ using System;
28
+
29
+ using System.Collections.Generic;
30
+
31
+ using System.ComponentModel;
32
+
33
+ using System.Data;
34
+
35
+ using System.Drawing;
36
+
37
+ using System.Linq;
38
+
39
+ using System.Text;
40
+
41
+ using System.Threading.Tasks;
42
+
43
+ using System.Windows.Forms;
44
+
45
+ using DxLibDLL;//DxLibを使用
46
+
47
+ using CoreTweet; //CoreTweetを使用
48
+
49
+ using System.IO;//FileInfoを使用
50
+
51
+ using SpeechLib; //音声認識用
52
+
53
+
54
+
55
+ namespace DesctopMascot
56
+
57
+ {
58
+
59
+ public partial class Form1 : Form
60
+
61
+ {
62
+
63
+ private int[] modelNum;
64
+
65
+ private string[] modelName;
66
+
67
+ private string[] modelPass;
68
+
69
+ private int modelHandle;
70
+
71
+ private int cameraHandle;
72
+
73
+ private int soundHandle;
74
+
75
+ private int nowModelIndex;
76
+
77
+ private int attachIndex;
78
+
79
+ private float totalTime;
80
+
81
+ private float playTime;
82
+
83
+ private const float playSpeed = 0.48f;
84
+
85
+ private int motionNum;
86
+
87
+ private const int maxNum = 2;
88
+
89
+ private Tokens token;
90
+
91
+ private int NowInput, EdgeInput, PrevInput;
92
+
93
+ private int Catch;
94
+
95
+ private int CatchMouseX, CatchMouseY;
96
+
97
+ private DX.VECTOR Catch3DModelPosition;
98
+
99
+ private DX.VECTOR Catch3DHitPosition;
100
+
101
+ private DX.VECTOR Catch2DHitPosition;
102
+
103
+ private DX.VECTOR scale;
104
+
105
+ private float rot;
106
+
107
+ private int musicIndex;
108
+
109
+ private SpeechLib.SpInProcRecoContext recognizerRule; //音声認識オブジェクト
110
+
111
+ private SpeechLib.ISpeechRecoGrammar recognizerGrammarRule; //音声認識のための言語モデル
112
+
113
+ private SpeechLib.ISpeechGrammarRule recognizerGrammarRuleGrammarRule; ////音声認識のための言語モデルのルールのトップレベルオブジェクト
114
+
115
+ private enum ModelNum
116
+
117
+ {
118
+
119
+ KAEDE,
120
+
121
+ RIN
122
+
123
+ }
124
+
125
+
126
+
127
+ private enum MusicNum
128
+
129
+ {
130
+
131
+ KOIKAZE
132
+
133
+ }
134
+
135
+
136
+
137
+ private enum MotionNum
138
+
139
+ {
140
+
141
+ FUYU,
142
+
143
+ FUYU2,
144
+
145
+ KOIKAZE
146
+
147
+ }
148
+
149
+
150
+
151
+ public Form1()
152
+
153
+ {
154
+
155
+ InitializeComponent();
156
+
157
+
158
+
159
+ //マウスのホイール動作の追加
160
+
161
+ MouseWheel += new MouseEventHandler(Form1_MouseWheel);
162
+
163
+
164
+
165
+
166
+
167
+ ClientSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); //画面サイズの設定
168
+
169
+ Text = "DesktopMascot"; //ウインドウの名前を設定
170
+
171
+ AllowDrop = true; //ドラッグ&ドロップを許可
172
+
173
+
174
+
175
+ token = Tokens.Create(""); //twitterアカウントの認証
176
+
177
+
178
+
179
+ DX.SetOutApplicationLogValidFlag(DX.FALSE); //Log.txtを生成しないように設定
180
+
181
+ DX.SetUserWindow(Handle); //DxLibの親ウインドウをこのフォームに設定
182
+
183
+ DX.SetZBufferBitDepth(24); //Zバッファの精度を変更
184
+
185
+ DX.DxLib_Init(); //DxLibの初期化処理
186
+
187
+ DX.SetDrawScreen(DX.DX_SCREEN_BACK); //描画先を裏画面に設定
188
+
189
+
190
+
191
+ modelHandle = DX.MV1LoadModel(modelPass[(int)ModelNum.KAEDE]);
192
+
193
+ cameraHandle = 0;
194
+
195
+ nowModelIndex = 0;
196
+
197
+ attachIndex = DX.MV1AttachAnim(modelHandle, motionNum, -1, DX.FALSE);
198
+
199
+ totalTime = DX.MV1GetAttachAnimTotalTime(modelHandle, attachIndex);
200
+
201
+ playTime = 0.0f;
202
+
203
+ scale = DX.MV1GetScale(modelHandle);
204
+
205
+ NowInput = 0;
206
+
207
+ EdgeInput = 0;
208
+
209
+ PrevInput = 0;
210
+
211
+ Catch = 0;
212
+
213
+ musicIndex = 0;
214
+
215
+ soundHandle = 0;
216
+
217
+
218
+
219
+ OnseiNinshiki();
220
+
221
+ }
222
+
223
+
224
+
225
+ public void MainLoop()
226
+
227
+ {
228
+
229
+ DX.ClearDrawScreen();//裏画面を消す
230
+
231
+
232
+
233
+ DX.DrawBox(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, DX.GetColor(1, 1, 1), DX.TRUE);//背景を設定(透過させる)
234
+
235
+
236
+
237
+ playTime += playSpeed;
238
+
239
+
240
+
241
+ //モーションの再生位置が終端まで来たら最初に戻す
242
+
243
+ if (playTime >= totalTime)
244
+
245
+ {
246
+
247
+ playTime = 0.0f;
248
+
249
+ }
250
+
251
+
252
+
253
+ DX.MV1SetAttachAnimTime(modelHandle, attachIndex, playTime);//モーションの再生位置を設定
254
+
255
+
256
+
257
+ ModelMove();
258
+
259
+
260
+
261
+ if (cameraHandle > 0)
262
+
263
+ {
264
+
265
+ // VMDカメラモーションのパラメータをDXライブラリの設定に反映させる
266
+
267
+ //SetupVMDCameraMotionParam(cameraHandle, playTime);
268
+
269
+ }
270
+
271
+ if (soundHandle > 0 && DX.CheckSoundMem(soundHandle) == 0)
272
+
273
+ {
274
+
275
+ DX.DeleteSoundMem(soundHandle);
276
+
277
+ }
278
+
279
+
280
+
281
+ if (modelHandle != 0)
282
+
283
+ {
284
+
285
+ DX.MV1DrawModel(modelHandle);//3Dモデルの描画
286
+
287
+ }
288
+
289
+
290
+
291
+ //ESCキーを押したら終了
292
+
293
+ if (DX.CheckHitKey(DX.KEY_INPUT_ESCAPE) != 0)
294
+
295
+ {
296
+
297
+ Close();
298
+
299
+ }
300
+
301
+
302
+
303
+ DX.ScreenFlip();//裏画面を表画面にコピー
304
+
305
+ }
306
+
307
+
308
+
309
+ private void Form1_FormClosed(object sender, FormClosedEventArgs e)
310
+
311
+ {
312
+
313
+ DX.DxLib_End();//DxLibの終了処理
314
+
315
+ }
316
+
317
+
318
+
319
+ private void OnseiNinshiki()
320
+
321
+ {
322
+
323
+ bool hit = false;
324
+
325
+ //ルール認識 音声認識オブジェクトの生成
326
+
327
+ recognizerRule = new SpeechLib.SpInProcRecoContext();
328
+
329
+ foreach(SpObjectToken recoperson in recognizerRule.Recognizer.GetRecognizers())
330
+
331
+ {
332
+
333
+ string language = recoperson.GetAttribute("Language");
334
+
335
+ //日本語かチェック
336
+
337
+ if(language == "411")
338
+
339
+ {
340
+
341
+ recognizerRule.Recognizer.Recognizer = recoperson;
342
+
343
+ hit = true;
344
+
345
+ break;
346
+
347
+ }
348
+
349
+ }
350
+
351
+ if(!hit)
352
+
353
+ {
354
+
355
+ MessageBox.Show("日本語認識が利用できません。\r\n日本語音声認識 MSSpeech_SR_ja-JP_TELE をインストールしてください。\r\n");
356
+
357
+ }
358
+
359
+ recognizerRule.Recognizer.AudioInput = CreateMicrofon();
360
+
361
+
362
+
363
+ //音声認識イベントでデリゲートによるコールバックを受ける
364
+
365
+ //認識の途中
366
+
367
+ recognizerRule.Hypothesis += delegate (int streamNumber, object streamPosition, SpeechLib.ISpeechRecoResult result)
368
+
369
+ {
370
+
371
+ string strText = result.PhraseInfo.GetText(0, -1, true);
372
+
373
+ };
374
+
375
+
376
+
377
+ //認識完了
378
+
379
+ recognizerRule.Recognition += delegate (int streamNumber, object streamPosition, SpeechLib.SpeechRecognitionType srt, SpeechLib.ISpeechRecoResult isrr)
380
+
381
+ {
382
+
383
+ string strText = isrr.PhraseInfo.GetText(0, -1, true);
384
+
385
+ MessageBox.Show(this, strText, "メニュー", MessageBoxButtons.OK, MessageBoxIcon.Information);
386
+
387
+ };
388
+
389
+ //ストリームに何かデータが来た(?)
390
+
391
+ this.recognizerRule.StartStream += delegate (int streamNumber, object streamPosition)
392
+
393
+ {
394
+
395
+ MessageBox.Show("おはよう", "メニュー", MessageBoxButtons.OK, MessageBoxIcon.Information);
396
+
397
+ };
398
+
399
+ //認識失敗
400
+
401
+ this.recognizerRule.FalseRecognition +=
402
+
403
+ delegate (int streamNumber, object streamPosition, SpeechLib.ISpeechRecoResult isrr)
404
+
405
+ {
406
+
407
+ MessageBox.Show("--ERROR!--", "メニュー", MessageBoxButtons.OK, MessageBoxIcon.Information);
408
+
409
+ };
410
+
411
+
412
+
413
+ //言語モデルの作成
414
+
415
+ recognizerGrammarRule = recognizerRule.CreateGrammar(0);
416
+
417
+ recognizerGrammarRule.Reset(0);
418
+
419
+
420
+
421
+ //言語モデルのルールのトップレベルを作成する
422
+
423
+ recognizerGrammarRuleGrammarRule = recognizerGrammarRule.Rules.Add("TopLevelRule", SpeechRuleAttributes.SRATopLevel | SpeechRuleAttributes.SRADynamic);
424
+
425
+ //文字列の追加.
426
+
427
+ recognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "りんごください");
428
+
429
+ recognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "バナナください");
430
+
431
+ recognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "らんらんるー");
432
+
433
+ recognizerGrammarRuleGrammarRule.InitialState.AddWordTransition(null, "私がムスカ大佐だ");
434
+
435
+
436
+
437
+ //ルールを反映させる。
438
+
439
+ recognizerGrammarRule.Rules.Commit();
440
+
441
+
442
+
443
+ //音声認識開始。(トップレベルのオブジェクトの名前で SpeechRuleState.SGDSActive を指定する.)
444
+
445
+ recognizerGrammarRule.CmdSetRuleState("TopLevelRule", SpeechRuleState.SGDSActive);
446
+
447
+ }
448
+
449
+
450
+
451
+ //マイクから読み取るため、マイク用のデバイスを指定する.
452
+
453
+ private SpeechLib.SpObjectToken CreateMicrofon()
454
+
455
+ {
456
+
457
+ SpeechLib.SpObjectTokenCategory objAudioTokenCategory = new SpeechLib.SpObjectTokenCategory();
458
+
459
+ objAudioTokenCategory.SetId(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech Server\v11.0\AudioInput", false);
460
+
461
+ SpeechLib.SpObjectToken objAudioToken = new SpeechLib.SpObjectToken();
462
+
463
+ objAudioToken.SetId(objAudioTokenCategory.Default, @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech Server\v11.0\AudioInput", false);
464
+
465
+ return objAudioToken;
466
+
467
+ }
468
+
469
+ ```
470
+
471
+ 文字数オーバーになるため関係ないと思われるところは省略しています。
472
+
473
+ どうかよろしくお願いいたします。