void Update() { if (speechManager == null) { speechManager = SpeechManager.Instance; } // use speech recognizer to control the mocap recorder if (speechManager != null && speechManager.IsSapiInitialized()) { if (speechManager.IsPhraseRecognized()) { string sPhraseTag = speechManager.GetPhraseTagRecognized(); switch (sPhraseTag) { case "RECORD": if (mocapRecorder) { mocapRecorder.StartRecording(); } break; case "STOP": if (mocapRecorder) { mocapRecorder.StopRecording(); } break; } speechManager.ClearPhraseRecognized(); } } // alternatively, use the Jump-button (space-key) if (Input.GetButtonDown("Jump")) { if (mocapRecorder) { if (!mocapRecorder.IsRecording()) { mocapRecorder.StartRecording(); } else { mocapRecorder.StopRecording(); } } } }
void FixedUpdate() { // get the speech manager instance if (speechManager == null) { speechManager = SpeechManager.Instance; } if (speechManager != null && speechManager.IsSapiInitialized()) { if (speechManager.IsPhraseRecognized()) { string sPhraseTag = speechManager.GetPhraseTagRecognized(); switch (sPhraseTag) { case "FORWARD": //GameObject m=GameObject.Find("Next"); levelLoaded = true; Application.LoadLevel(3); NextPage(); break; case "Next": //GameObject m=GameObject.Find("Next"); //levelLoaded = true; // Application.LoadLevel (3); //NextPage (); // levelLoaded = true; // Application.LoadLevel (3); break; case "Back": //GameObject m=GameObject.Find("Next"); //levelLoaded = true; // Application.LoadLevel (3); LastPage(); break; } speechManager.ClearPhraseRecognized(); } } else { Debug.Log("FAIL TO RECOGNIZE "); } }
void Update() { if (speechManager == null) { speechManager = SpeechManager.Instance; } if (speechManager != null && speechManager.IsSapiInitialized()) { if (speechManager.IsPhraseRecognized()) { string sPhraseTag = speechManager.GetPhraseTagRecognized(); switch (sPhraseTag) { case "RECORD": if (saverPlayer) { saverPlayer.StartRecording(); } break; case "PLAY": if (saverPlayer) { saverPlayer.StartPlaying(); } break; case "STOP": if (saverPlayer) { saverPlayer.StopRecordingOrPlaying(); } break; } speechManager.ClearPhraseRecognized(); } } }
void FixedUpdate() { if (speechManager != null && speechManager.IsSapiInitialized()) { if (speechManager.IsPhraseRecognized()) { string sPhraseTag = speechManager.GetPhraseTagRecognized(); switch (sPhraseTag) { case "FORWARD": walkSpeed = 0.2f; walkDirection = 0f; break; case "BACK": walkSpeed = -0.2f; walkDirection = 0f; break; case "LEFT": walkDirection = -0.2f; if (walkSpeed == 0f) { walkSpeed = 0.2f; } break; case "RIGHT": walkDirection = 0.2f; if (walkSpeed == 0f) { walkSpeed = 0.2f; } break; case "RUN": walkSpeed = 0.5f; walkDirection = 0f; break; case "STOP": walkSpeed = 0f; walkDirection = 0f; break; case "JUMP": jumpNow = true; walkSpeed = 0.5f; walkDirection = 0f; break; case "HELLO": waveNow = true; walkSpeed = 0.0f; walkDirection = 0f; break; } speechManager.ClearPhraseRecognized(); } } else { walkDirection = Input.GetAxis("Horizontal"); // setup h variable as our horizontal input axis walkSpeed = Input.GetAxis("Vertical"); // setup v variables as our vertical input axis jumpNow = Input.GetButtonDown("Jump"); waveNow = Input.GetButtonDown("Jump"); } anim.SetFloat("Speed", walkSpeed); // set our animator's float parameter 'Speed' equal to the vertical input axis anim.SetFloat("Direction", walkDirection); // set our animator's float parameter 'Direction' equal to the horizontal input axis anim.speed = animSpeed; // set the speed of our animator to the public variable 'animSpeed' anim.SetLookAtWeight(lookWeight); // set the Look At Weight - amount to use look at IK vs using the head's animation currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // set our currentState variable to the current state of the Base Layer (0) of animation if (anim.layerCount == 2) { layer2CurrentState = anim.GetCurrentAnimatorStateInfo(1); // set our layer2CurrentState variable to the current state of the second Layer (1) of animation } // LOOK AT ENEMY // // if we hold Alt.. // if(Input.GetButton("Fire2")) // { // // ...set a position to look at with the head, and use Lerp to smooth the look weight from animation to IK (see line 54) // anim.SetLookAtPosition(enemy.position); // lookWeight = Mathf.Lerp(lookWeight,1f,Time.deltaTime*lookSmoother); // } // // else, return to using animation for the head by lerping back to 0 for look at weight // else // { // lookWeight = Mathf.Lerp(lookWeight,0f,Time.deltaTime*lookSmoother); // } // STANDARD JUMPING // if we are currently in a state called Locomotion (see line 25), then allow Jump input (Space) to set the Jump bool parameter in the Animator to true if (currentBaseState.nameHash == locoState) { if (jumpNow) { jumpNow = false; anim.SetBool("Jump", true); } } // if we are in the jumping state... else if (currentBaseState.nameHash == jumpState) { // ..and not still in transition.. if (!anim.IsInTransition(0)) { if (useCurves) { // ..set the collider height to a float curve in the clip called ColliderHeight col.height = anim.GetFloat("ColliderHeight"); } // reset the Jump bool so we can jump again, and so that the state does not loop anim.SetBool("Jump", false); } // Raycast down from the center of the character.. Ray ray = new Ray(transform.position + Vector3.up, -Vector3.up); RaycastHit hitInfo = new RaycastHit(); if (Physics.Raycast(ray, out hitInfo)) { // ..if distance to the ground is more than 1.75, use Match Target if (hitInfo.distance > 1.75f) { // MatchTarget allows us to take over animation and smoothly transition our character towards a location - the hit point from the ray. // Here we're telling the Root of the character to only be influenced on the Y axis (MatchTargetWeightMask) and only occur between 0.35 and 0.5 // of the timeline of our animation clip anim.MatchTarget(hitInfo.point, Quaternion.identity, AvatarTarget.Root, new MatchTargetWeightMask(new Vector3(0, 1, 0), 0), 0.35f, 0.5f); } } } // JUMP DOWN AND ROLL // // if we are jumping down, set our Collider's Y position to the float curve from the animation clip - // // this is a slight lowering so that the collider hits the floor as the character extends his legs // else if (currentBaseState.nameHash == jumpDownState) // { // col.center = new Vector3(0, anim.GetFloat("ColliderY"), 0); // } // // // if we are falling, set our Grounded boolean to true when our character's root // // position is less that 0.6, this allows us to transition from fall into roll and run // // we then set the Collider's Height equal to the float curve from the animation clip // else if (currentBaseState.nameHash == fallState) // { // col.height = anim.GetFloat("ColliderHeight"); // } // // // if we are in the roll state and not in transition, set Collider Height to the float curve from the animation clip // // this ensures we are in a short spherical capsule height during the roll, so we can smash through the lower // // boxes, and then extends the collider as we come out of the roll // // we also moderate the Y position of the collider using another of these curves on line 128 // else if (currentBaseState.nameHash == rollState) // { // if(!anim.IsInTransition(0)) // { // if(useCurves) // col.height = anim.GetFloat("ColliderHeight"); // // col.center = new Vector3(0, anim.GetFloat("ColliderY"), 0); // // } // } // IDLE // check if we are at idle, if so, let us Wave! else if (currentBaseState.nameHash == idleState) { if (waveNow) { waveNow = false; anim.SetBool("Wave", true); } } // if we enter the waving state, reset the bool to let us wave again in future if (layer2CurrentState.nameHash == waveState) { anim.SetBool("Wave", false); } }
void Update() { int recHostId; int connectionId; int recChannelId; int dataSize; bool connListUpdated = false; if (backgroundImage && backgroundImage.texture == null) { backgroundImage.texture = manager ? manager.GetUsersLblTex() : null; } if (faceManager == null) { faceManager = FacetrackingManager.Instance; } if (gestureManager == null) { gestureManager = VisualGestureManager.Instance; } if (speechManager == null) { speechManager = SpeechManager.Instance; } try { byte error = 0; NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out recChannelId, recBuffer, bufferSize, out dataSize, out error); switch (recData) { case NetworkEventType.Nothing: //1 break; case NetworkEventType.ConnectEvent: //2 if (recHostId == serverHostId && recChannelId == serverChannelId && !dictConnection.ContainsKey(connectionId)) { HostConnection conn = new HostConnection(); conn.hostId = recHostId; conn.connectionId = connectionId; conn.channelId = recChannelId; conn.keepAlive = true; conn.reqDataType = "ka,kb,km,kh"; //conn.matrixSent = false; dictConnection[connectionId] = conn; connListUpdated = true; //LogToConsole(connectionId + "-conn: " + conn.reqDataType); } // // reset chunked face messages // sendFvMsg = string.Empty; // sendFvNextOfs = 0; // // sendFtMsg = string.Empty; // sendFtNextOfs = 0; break; case NetworkEventType.DataEvent: //3 if (recHostId == serverHostId && recChannelId == serverChannelId && dictConnection.ContainsKey(connectionId)) { HostConnection conn = dictConnection[connectionId]; int decompSize = 0; if (decompressor != null && (recBuffer[0] > 127 || recBuffer[0] < 32)) { decompSize = decompressor.Decompress(recBuffer, 0, compressBuffer, 0, dataSize); } else { System.Buffer.BlockCopy(recBuffer, 0, compressBuffer, 0, dataSize); decompSize = dataSize; } string sRecvMessage = System.Text.Encoding.UTF8.GetString(compressBuffer, 0, decompSize); if (sRecvMessage.StartsWith("ka")) { if (sRecvMessage == "ka") // vr-examples v1.0 keep-alive message { sRecvMessage = "ka,kb,km,kh"; } conn.keepAlive = true; conn.reqDataType = sRecvMessage; dictConnection[connectionId] = conn; //LogToConsole(connectionId + "-recv: " + conn.reqDataType); // check for SR phrase-reset int iIndexSR = sRecvMessage.IndexOf(",sr"); if (iIndexSR >= 0 && speechManager) { speechManager.ClearPhraseRecognized(); //LogToConsole("phrase cleared"); } } } break; case NetworkEventType.DisconnectEvent: //4 if (dictConnection.ContainsKey(connectionId)) { dictConnection.Remove(connectionId); connListUpdated = true; } break; } if (connListUpdated) { // get all connection IDs alConnectionId.Clear(); alConnectionId.AddRange(dictConnection.Keys); // display the number of connections StringBuilder sbConnStatus = new StringBuilder(); sbConnStatus.AppendFormat("Server running: {0} connection(s)", dictConnection.Count); foreach (int connId in dictConnection.Keys) { HostConnection conn = dictConnection[connId]; int iPort = 0; string sAddress = string.Empty; NetworkID network; NodeID destNode; NetworkTransport.GetConnectionInfo(conn.hostId, conn.connectionId, out sAddress, out iPort, out network, out destNode, out error); if (error == (int)NetworkError.Ok) { sbConnStatus.AppendLine().Append(" ").Append(sAddress).Append(":").Append(iPort); } } LogToConsole(sbConnStatus.ToString()); if (connStatusText) { connStatusText.text = sbConnStatus.ToString(); } } // send body frame to available connections const char delimiter = ','; string sBodyFrame = manager ? manager.GetBodyFrameData(ref liRelTime, ref fCurrentTime, delimiter) : string.Empty; if (sBodyFrame.Length > 0 && dictConnection.Count > 0) { StringBuilder sbSendMessage = new StringBuilder(); bool bFaceParamsRequested = IsFaceParamsRequested(); sbSendMessage.Append(manager.GetWorldMatrixData(delimiter)).Append('|'); sbSendMessage.Append(sBodyFrame).Append('|'); sbSendMessage.Append(manager.GetBodyHandData(ref liRelTime, delimiter)).Append('|'); if (bFaceParamsRequested && faceManager && faceManager.IsFaceTrackingInitialized()) { sbSendMessage.Append(faceManager.GetFaceParamsAsCsv(delimiter)).Append('|'); } if (gestureManager && gestureManager.IsVisualGestureInitialized()) { sbSendMessage.Append(gestureManager.GetGestureDataAsCsv(delimiter)).Append('|'); } if (speechManager && speechManager.IsSapiInitialized()) { sbSendMessage.Append(speechManager.GetSpeechDataAsCsv(delimiter)).Append('|'); } if (sbSendMessage.Length > 0 && sbSendMessage[sbSendMessage.Length - 1] == '|') { sbSendMessage.Remove(sbSendMessage.Length - 1, 1); } byte[] btSendMessage = System.Text.Encoding.UTF8.GetBytes(sbSendMessage.ToString()); //Debug.Log("Message " + sbSendMessage.Length + " chars: " + sbSendMessage.ToString()); //Debug.Log("Encoded into " + btSendMessage.Length + " bytes: " + ByteArrayToString(btSendMessage, btSendMessage.Length)); int compSize = 0; if (compressor != null && btSendMessage.Length > 100 && !websocketHost) { compSize = compressor.Compress(btSendMessage, 0, btSendMessage.Length, compressBuffer, 0); } else { System.Buffer.BlockCopy(btSendMessage, 0, compressBuffer, 0, btSendMessage.Length); compSize = btSendMessage.Length; } //Debug.Log("Compressed into " + compSize + " bytes: " + ByteArrayToString(compressBuffer, compSize)); // // check face-tracking requests // bool bFaceParams = false, bFaceVertices = false, bFaceUvs = false, bFaceTriangles = false; // if(faceManager && faceManager.IsFaceTrackingInitialized()) // CheckFacetrackRequests(out bFaceParams, out bFaceVertices, out bFaceUvs, out bFaceTriangles); // // byte[] btFaceParams = null; // if(bFaceParams) // { // string sFaceParams = faceManager.GetFaceParamsAsCsv(); // if(!string.IsNullOrEmpty(sFaceParams)) // btFaceParams = System.Text.Encoding.UTF8.GetBytes(sFaceParams); // } // // // next chunk of data for face vertices // byte[] btFaceVertices = null; // string sFvMsgHead = string.Empty; // GetNextFaceVertsChunk(bFaceVertices, bFaceUvs, ref btFaceVertices, out sFvMsgHead); // // // next chunk of data for face triangles // byte[] btFaceTriangles = null; // string sFtMsgHead = string.Empty; // GetNextFaceTrisChunk(bFaceTriangles, ref btFaceTriangles, out sFtMsgHead); foreach (int connId in alConnectionId) { HostConnection conn = dictConnection[connId]; if (conn.keepAlive) { conn.keepAlive = false; dictConnection[connId] = conn; if (conn.reqDataType != null && conn.reqDataType.Contains("kb,")) { //LogToConsole(conn.connectionId + "-sendkb: " + conn.reqDataType); error = 0; //if(!NetworkTransport.Send(conn.hostId, conn.connectionId, conn.channelId, btSendMessage, btSendMessage.Length, out error)) if (!NetworkTransport.Send(conn.hostId, conn.connectionId, conn.channelId, compressBuffer, compSize, out error)) { string sMessage = "Error sending body data via conn " + conn.connectionId + ": " + (NetworkError)error; LogErrorToConsole(sMessage); if (serverStatusText) { serverStatusText.text = sMessage; } } } // if(bFaceParams && btFaceParams != null && // conn.reqDataType != null && conn.reqDataType.Contains("fp,")) // { // //Debug.Log(conn.connectionId + "-sendfp: " + conn.reqDataType); // // error = 0; // if(!NetworkTransport.Send(conn.hostId, conn.connectionId, conn.channelId, btFaceParams, btFaceParams.Length, out error)) // { // string sMessage = "Error sending face params via conn " + conn.connectionId + ": " + (NetworkError)error; // Debug.LogError(sMessage); // // if(serverStatusText) // { // serverStatusText.text = sMessage; // } // } // } // // if(bFaceVertices && btFaceVertices != null && // conn.reqDataType != null && conn.reqDataType.Contains("fv,")) // { // //Debug.Log(conn.connectionId + "-sendfv: " + conn.reqDataType + " - " + sFvMsgHead); // // error = 0; // if(!NetworkTransport.Send(conn.hostId, conn.connectionId, conn.channelId, btFaceVertices, btFaceVertices.Length, out error)) // { // string sMessage = "Error sending face verts via conn " + conn.connectionId + ": " + (NetworkError)error; // Debug.LogError(sMessage); // // if(serverStatusText) // { // serverStatusText.text = sMessage; // } // } // } // // if(bFaceTriangles && btFaceTriangles != null && // conn.reqDataType != null && conn.reqDataType.Contains("ft,")) // { // //Debug.Log(conn.connectionId + "-sendft: " + conn.reqDataType + " - " + sFtMsgHead); // // error = 0; // if(!NetworkTransport.Send(conn.hostId, conn.connectionId, conn.channelId, btFaceTriangles, btFaceTriangles.Length, out error)) // { // string sMessage = "Error sending face tris via conn " + conn.connectionId + ": " + (NetworkError)error; // Debug.LogError(sMessage); // // if(serverStatusText) // { // serverStatusText.text = sMessage; // } // } // } } } } } catch (System.Exception ex) { LogErrorToConsole(ex.Message + "\n" + ex.StackTrace); if (serverStatusText) { serverStatusText.text = ex.Message; } } }
void FixedUpdate() { // get the speech manager instance if (speechManager == null) { speechManager = SpeechManager.Instance; } if (speechManager != null && speechManager.IsSapiInitialized()) { if (speechManager.IsPhraseRecognized()) { string sPhraseTag = speechManager.GetPhraseTagRecognized(); switch (sPhraseTag) { case "FORWARD": walkSpeed = 0.2f; walkDirection = 0f; break; case "BACK": walkSpeed = -0.2f; walkDirection = 0f; break; case "LEFT": walkDirection = -0.2f; if (walkSpeed == 0f) { walkSpeed = 0.2f; } break; case "RIGHT": walkDirection = 0.2f; if (walkSpeed == 0f) { walkSpeed = 0.2f; } break; case "RUN": walkSpeed = 0.5f; walkDirection = 0f; break; case "STOP": walkSpeed = 0f; walkDirection = 0f; break; case "JUMP": jumpNow = true; walkSpeed = 0.5f; walkDirection = 0f; break; case "HELLO": waveNow = true; walkSpeed = 0.0f; walkDirection = 0f; break; } speechManager.ClearPhraseRecognized(); } } else { walkDirection = Input.GetAxis("Horizontal"); // setup h variable as our horizontal input axis walkSpeed = Input.GetAxis("Vertical"); // setup v variables as our vertical input axis jumpNow = Input.GetButtonDown("Jump"); waveNow = Input.GetButtonDown("Jump"); } anim.SetFloat("Speed", walkSpeed); // set our animator's float parameter 'Speed' equal to the vertical input axis anim.SetFloat("Direction", walkDirection); // set our animator's float parameter 'Direction' equal to the horizontal input axis anim.speed = animSpeed; // set the speed of our animator to the public variable 'animSpeed' anim.SetLookAtWeight(lookWeight); // set the Look At Weight - amount to use look at IK vs using the head's animation currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // set our currentState variable to the current state of the Base Layer (0) of animation if (anim.layerCount == 2) { layer2CurrentState = anim.GetCurrentAnimatorStateInfo(1); // set our layer2CurrentState variable to the current state of the second Layer (1) of animation } // if we are currently in a state called Locomotion (see line 25), then allow Jump input (Space) to set the Jump bool parameter in the Animator to true //if (currentBaseState.nameHash == locoState) //{ // if(jumpNow) // { // jumpNow = false; // anim.SetBool("Jump", true); // } //} // if we are in the jumping state... // else if (currentBaseState.nameHash == jumpState) // { // // ..and not still in transition.. // if(!anim.IsInTransition(0)) // { // if(useCurves) // // ..set the collider height to a float curve in the clip called ColliderHeight // col.height = anim.GetFloat("ColliderHeight"); // // reset the Jump bool so we can jump again, and so that the state does not loop // anim.SetBool("Jump", false); // } // // Raycast down from the center of the character.. // Ray ray = new Ray(transform.position + Vector3.up, -Vector3.up); // RaycastHit hitInfo = new RaycastHit(); // if (Physics.Raycast(ray, out hitInfo)) // { // // ..if distance to the ground is more than 1.75, use Match Target // if (hitInfo.distance > 1.75f) // { // // MatchTarget allows us to take over animation and smoothly transition our character towards a location - the hit point from the ray. // // Here we're telling the Root of the character to only be influenced on the Y axis (MatchTargetWeightMask) and only occur between 0.35 and 0.5 // // of the timeline of our animation clip // anim.MatchTarget(hitInfo.point, Quaternion.identity, AvatarTarget.Root, new MatchTargetWeightMask(new Vector3(0, 1, 0), 0), 0.35f, 0.5f); // } // } //} // check if we are at idle, if so, let us Wave! //else if (currentBaseState.nameHash == idleState) //{ // if(waveNow) // { // waveNow = false; // anim.SetBool("Wave", true); // } //} // if we enter the waving state, reset the bool to let us wave again in future //if(layer2CurrentState.nameHash == waveState) //{ // anim.SetBool("Wave", false); //} }
void Update() { if (speechManager == null) { speechManager = SpeechManager.Instance; } if (speechManager != null && speechManager.IsSapiInitialized()) { if (speechManager.IsPhraseRecognized()) { string sPhraseTag = speechManager.GetPhraseTagRecognized(); switch (sPhraseTag) { case "RECORD": if (saverPlayer) { saverPlayer.StartRecording(); } break; case "PLAY": if (saverPlayer) { saverPlayer.StartPlaying(); } break; case "STOP": if (saverPlayer) { saverPlayer.StopRecordingOrPlaying(); } break; } speechManager.ClearPhraseRecognized(); } } // alternatively, use the keyboard if (Input.GetButtonDown("Jump")) // start or stop recording { if (saverPlayer) { if (!saverPlayer.IsRecording()) { saverPlayer.StartRecording(); } else { saverPlayer.StopRecordingOrPlaying(); } } } if (Input.GetButtonDown("Fire1")) // start or stop playing { if (saverPlayer) { if (!saverPlayer.IsPlaying()) { saverPlayer.StartPlaying(); } else { saverPlayer.StopRecordingOrPlaying(); } } } }