Skip to content

Instantly share code, notes, and snippets.

@bibinba
Created February 23, 2019 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bibinba/27599af6e8205cdfe290b2d905fad1b2 to your computer and use it in GitHub Desktop.
Save bibinba/27599af6e8205cdfe290b2d905fad1b2 to your computer and use it in GitHub Desktop.
ジョジョの音声認識でソフト&ウェットとザ・ワールド
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Text;
using UnityEngine.Windows.Speech;
using UnityEngine.PostProcessing;
public class oyako : MonoBehaviour
{
private KeywordController keyCon;
private string[][] keywords;
public GameObject syabon;
public GameObject syabon1;
public AudioSource mahou;
public AudioSource mizu;
public AudioSource kaizyo;
private int a = 0;
public float amplitude = 0.01f; // 振幅
private int frameCnt = 0; // フレームカウント
// Start is called before the first frame update
void Start()
{
keywords = new string[3][];
keywords[0] = new string[] { "soft and wet", "soft" };//ひらがなでもカタカナでもいい
keywords[1] = new string[] { "ワールド", "ザワールド" };
keywords[2] = new string[] { "そしてときはうごきだす", "うごけ" };
keyCon = new KeywordController(keywords, true);//keywordControllerのインスタンスを作成
keyCon.SetKeywords();//KeywordRecognizerにkeywordsを設定する
keyCon.StartRecognizing(0);
keyCon.StartRecognizing(1);
keyCon.StartRecognizing(2);//シーン中で音声認識を始めたいときに呼び出す
// keyCon.StartRecognizing(1);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
syabon.transform.parent = null;
syabon1.transform.parent = null;
}
if (keyCon.hasRecognized[0])///ソフト&ウェット
{
mizu.Play(0);
syabon.transform.parent = null;
syabon1.transform.parent = null;
syabon.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
syabon1.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
Debug.Log("ソフト&ウェット");
keyCon.hasRecognized[0] = false;
a = 1;
}
if (keyCon.hasRecognized[1])///色が変わる
{
mahou.Play();
GetComponent<PostProcessingBehaviour>().enabled = true;
Debug.Log("ザ・ワールド");
keyCon.hasRecognized[1] = false;
a = 2;
}
if (keyCon.hasRecognized[2])///時が動き出す
{
kaizyo.Play();
GetComponent<PostProcessingBehaviour>().enabled = false;
Debug.Log("そして時は動き出す");
keyCon.hasRecognized[2] = false;
a = 1;
}
}
void FixedUpdate()
{
if (a == 1)
{
frameCnt += 1;
if (10000 <= frameCnt)
{
frameCnt = 0;
}
if (0 == frameCnt % 2)
{
// 上下に振動させる(ふわふわを表現)
float posYSin = Mathf.Sin(2.0f * Mathf.PI * (float)(frameCnt % 200) / (200.0f - 1.0f));
iTween.MoveAdd(syabon, new Vector3(0, amplitude * posYSin, 0), 0.0f);
iTween.MoveAdd(syabon1, new Vector3(0, amplitude * posYSin, 0), 0.0f);
}
}
if (a == 2)
{
iTween.Stop(syabon, "move");
iTween.Stop(syabon1, "move");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment