Unity Watson を使ってサクッと音声認識をさせみる #2

前回 UnityとWatsonを使って自分の声を認識させてみました。

ちなみに前回Watsonの料金プランを載せていなかったので載せておきます。

ライトプランだと1ヶ月無料で100分は使えるみたいです。


今回は、前回出来たものを元に背景の色を変えてみようと思います。

前回使用した、ExampleStreaming.csを参考に新しくScriptを書き換えます。

 private void OnRecognize(SpeechRecognitionEvent result, Dictionary<string, object> customData)
   {
       if (result != null && result.results.Length > 0)
       {
           foreach (var res in result.results)
           {
               foreach (var alt in res.alternatives)
               {
                   string text = string.Format("{0} ({1}, {2:0.00})\n", alt.transcript, res.final ? "Final" : "Interim", alt.confidence);
					
                   ResultsField.text = text;
		   ChangeColor(alt.transcript.TrimEnd());

               }

           }
       }
   }
   

void ChangeColor(string color){
	if(color.Contains ("赤")) {
		cam.backgroundColor = Color.red;
	}  
	if(color.Contains ("青")) {
		cam.backgroundColor = Color.blue;
	}  
	if(color.Contains ("黄")) {
		cam.backgroundColor = Color.yellow;
	} 
}

赤、青、黄色と言った時に認識した色に背景を変更させてみました。(Inten)

指定した色に背景が変わっていると思います。

黄色と言った時にヒーローと認識されるなど、認識精度があまいところもあったりします。(自分の発音が悪いかも)





この記事が気に入ったらサポートをしてみませんか?