Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by prabhhav · Mar 12, 2019 at 12:14 PM · speechvoice

How can I change the color of the cube with speech recognition ?

How can I change colour of cube with voice/speech. I have sample code with me

1) VoiceController using UnityEngine; using UnityEngine.UI;

public class VoiceController : MonoBehaviour {

 AndroidJavaObject activity;
 AndroidJavaObject plugin;

 public delegate void OnResultRecieved(string result);
 public static OnResultRecieved resultRecieved;

 private void Start() {
     InitPlugin();
 }

 void InitPlugin() {
     AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

     activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
     
     activity.Call("runOnUiThread", new AndroidJavaRunnable(() => {
             plugin = new AndroidJavaObject(
             "com.example.matthew.plugin.VoiceBridge");
     }));

     activity.Call("runOnUiThread", new AndroidJavaRunnable(() => {
         plugin.Call("StartPlugin");
     }));
 }

 /// <summary>
 /// gets called via SendMessage from the android plugin GameObject must be called "VoiceController"
 /// </summary>
 /// <param name="recognizedText">recognizedText.</param>
 public void OnVoiceResult(string recognizedText) {
     Debug.Log(recognizedText);
     resultRecieved?.Invoke(recognizedText);
 }

 /// <summary>
 /// gets called via SendMessage from the android plugin
 /// </summary>
 /// <param name="error">Error.</param>
 public void OnErrorResult(string error) {
     Debug.Log(error);
 }

 public void GetSpeech() {
     // Calls the function from the jar file
     activity.Call("runOnUiThread", new AndroidJavaRunnable(() => {
         plugin.Call("StartSpeaking");
     }));
 }

}

2) VoiceTest using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

[RequireComponent(typeof(VoiceController))] public class VoiceTest : MonoBehaviour {

 public Text uiText;

 VoiceController voiceController;

 public void GetSpeech() {
     voiceController.GetSpeech();
 }

 void Start() {
     voiceController = GetComponent<VoiceController>();
 }

 void OnEnable() {
     VoiceController.resultRecieved += OnVoiceResult;
 }

 void OnDisable() {
     VoiceController.resultRecieved -= OnVoiceResult;
 }

 void OnVoiceResult(string text) {
     uiText.text = text;
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Mar 12, 2019 at 12:22 PM

in the onvoiceresult method

 void OnVoiceResult(string text) {
      if(text == Color.green){ mat.color = Color.green; }//mat is just the material of the gamobject you want to change just assign in the inspector.
      uiText.text = text;
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image prabhhav · Mar 12, 2019 at 02:15 PM 0
Share

Thank you for the help but it is still showing errors

avatar image xxmariofer prabhhav · Mar 12, 2019 at 02:21 PM 0
Share

Color.green.ToString() i missed that

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

101 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dictation Recognizer does not recognize words 0 Answers

how to use Android's speechrecognizer in unity ? 0 Answers

iOS and Android accessibility 1 Answer

I wanted to know whether is it possible to use the SpeechRecognizer API in Unity Project to make an Android App? If yes, then how? 0 Answers

DictationRecognizer stops working after a random period of time 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges