1. Before updating to Windows 10 you may need to return your Pro license. More information here

Voice recognition in Unity?

Discussion in 'Scripting' started by allanjjj, Feb 22, 2012.

  1. allanjjj

    allanjjj

    Joined:
    Jan 4, 2012
    Messages:
    15
    Is there any plugin or library for Unity to do voice/speech recognition? Many thanks~
     
  2. Crash-Konijn

    Crash-Konijn

    Joined:
    Mar 4, 2010
    Messages:
    190
  3. tonyd

    tonyd

    Joined:
    Jun 2, 2009
    Messages:
    1,224
    You know, in some forums I've participated in, telling someone to "just google it" is a ban-able offense.

    If you don't know the answer, maybe you should avoid the thread entirely?
     
    UltimosJN likes this.
  4. Crash-Konijn

    Crash-Konijn

    Joined:
    Mar 4, 2010
    Messages:
    190
    Sorry my bad, I guess its not my day... I just got a littly cracky this morning about these topics. Still, there's also a thing called google first and then ask on the forum ;-)

    If you google that you can see that there are several topics about the same question so there should be an answer on this question... If I ask a question I can guarantee you that I've been on every topic/question/link I could find on google about the problem I have... It would be better if the question was something like:

    "Hey guys, I've been looking on the internet for hours but I can't find an answer that satisfies my needs. I found this, this and this info but no-one has ever posted a real answer on that so I thought I give it another shot... "

    Or he could already have found his answer. But again, sorry, I should not have done that, I'll just keep my mouth shut with such questions in future :)
     
  5. Catsoft-Studios

    Catsoft-Studios

    Joined:
    Jan 15, 2011
    Messages:
    94
    Maybe it's not what you are looking for, but if you are planning to use a webplayer with your project, you could try using the html5 Google Chrome voice recognition.

    Just make a text input and enable speech recognition. Then grab the text and use it in Unity.
     
  6. allanjjj

    allanjjj

    Joined:
    Jan 4, 2012
    Messages:
    15
    I would like to create a game in exe format, not for webplayer. Maybe for mobile also. Is there any good solution for that?
     
  7. Catsoft-Studios

    Catsoft-Studios

    Joined:
    Jan 15, 2011
    Messages:
    94
    If you want to create an .apk for Android, there must be a way to do it. I've made some projects for Android and I've used Speech Recognition. The thing is that I don't know if you can use this API in Unity.

    And for Windows... no idea.
     
  8. Kith000

    Kith000

    Joined:
    Dec 21, 2012
    Messages:
    2
    I googled "voice recognition in unity", found this thread, found a link to the "let me google that for you" thing. Now I'm stuck in an infinite loop. Thanks a lot
     
    luispdm likes this.
  9. phil_g

    phil_g

    Joined:
    May 31, 2013
    Messages:
    1
    If somebody is still interested, I could add some words into the thread.

    I am currently working on the project where I'm trying to use Google Voice API as a voice recognition service. Implementation is fairly simple using some external modules.

    A sequence is as following: record and save wav -> convert wav to flac -> send flac to Google -> parse JSON response. In Unity on Windo$e I'm at last step now - having some issues with parsing JSON. The rest of the process is quite ok, except it does not work as exe or apk lol (there is a problem with the Cuetools lib).

    Here is code that makes a request and gets a response:

    Code (csharp):
    1.  
    2. filepath = SavWav.Save("recording", _goAudioSource.clip); //save file from recording using SavWav lib
    3. const string flacName = "tmpFlac";
    4. int sampleRate = SoundTools.Wav2Flac(filepath, flacName); //get sample rate from SoundTools lib
    5.  
    6. private IEnumerator WwwGoogleSpeechRequest(String flacName, int sampleRate)
    7.     {
    8.         const string url = "http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium〈=ru-RU";
    9.  
    10.         Debug.Log("Entering request method");
    11.  
    12.         byte[] postData = File.ReadAllBytes(flacName);
    13.  
    14.         Debug.Log("Read flac file. Size: " + postData.Length + " bytes");
    15.  
    16.         //set up POST request parameters
    17.         var form = new WWWForm();
    18.  
    19.         var headers = form.headers;
    20.        
    21.         headers["Method"] = "POST";
    22.         headers["Content-Type"] = "audio/x-flac; rate=" + sampleRate;
    23.         headers["Content-Length"] = postData.Length;
    24.         headers["Accept"] = "application/json";
    25.  
    26.         form.AddBinaryData("fileUpload", postData, "flacFile", "audio/x-flac; rate=" + sampleRate);
    27.         var httpRequest = new WWW(url, form.data, headers);
    28.  
    29.         yield return httpRequest;
    30.  
    31.         if (httpRequest.isDone  string.IsNullOrEmpty(httpRequest.error))
    32.         {
    33.             //_response = String.Format("Request succeeded. Request data: {0}{1}", Environment.NewLine, httpRequest.text);
    34.             _response = httpRequest.text.Substring(1);
    35.             Debug.Log(_response);
    36.             _response = ParseResponse(_response);
    37.             Debug.Log("Request succeeded. Request data: " + _response);
    38.         }
    39.         else
    40.         {
    41.             _response = String.Format("Request failed with Error: {0}{1}", Environment.NewLine, httpRequest.error);
    42.             Debug.Log(String.Format("Request failed with Error: {0}", httpRequest.error));
    43.         }
    44.     }
    45.  
    It works when I click Play in Unity, however there are still many bugs all over the whole voice-to-text process, so the solution is not quite useable when built as exe or apk or something else.
     
    Last edited: Jun 7, 2013
  10. superjayman

    superjayman

    Joined:
    May 31, 2013
    Messages:
    32
    Where is this function sampleRate = SoundTools.Wav2Flac(filepath, flacName);

    can you please post a more complete code, where did you get SoundTools?? Thanks
     
  11. Sylafrs

    Sylafrs

    Joined:
    Jun 25, 2013
    Messages:
    8
  12. scottmontgomerie

    scottmontgomerie

    Joined:
    May 6, 2013
    Messages:
    3
  13. arada

    arada

    Joined:
    May 25, 2011
    Messages:
    16
    I try use it but not work. Its part some wider project. How can I use it in practice?