Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Voice recognition in Unity?

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

  1. allanjjj

    allanjjj

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

    CrashKonijn

    Joined:
    Mar 4, 2010
    Posts:
    245
  3. tonyd

    tonyd

    Joined:
    Jun 2, 2009
    Posts:
    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?
     
  4. CrashKonijn

    CrashKonijn

    Joined:
    Mar 4, 2010
    Posts:
    245
    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
    Posts:
    702
    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
    Posts:
    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
    Posts:
    702
    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
    Posts:
    7
    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
     
    enne30, dkrprasetya, taguados and 6 others like this.
  9. phil_g

    phil_g

    Joined:
    May 31, 2013
    Posts:
    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
    josepaternina likes this.
  10. superjayman

    superjayman

    Joined:
    May 31, 2013
    Posts:
    185
    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
    Posts:
    65
  12. scottmontgomerie

    scottmontgomerie

    Joined:
    May 6, 2013
    Posts:
    4
  13. arada

    arada

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

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    515
    Yup I agree Kith000 I have been at this trying to find useful, step by step information on HOW the bloody hell to get voice recognition working in Unity for the last 2 years now and it's an infinite loop of the classic "Run Around."
    Why is this such a difficult thing to find helpful information on? It's just absolutely frustrating! There are loads of examples, videos and so on, on on and bloody on but no one takes the time to explain properly how it's done, what gets downloaded where it goes how you set it up etcetera.... Being on a Mac is probably even tougher.

    Getting so frustrated with not finding any real useful information on HOW TO DO THIS?
     
    KarolinaH and b33rdy like this.
  15. FrostweepGames

    FrostweepGames

    Joined:
    Jan 2, 2015
    Posts:
    264
    Last edited: Nov 18, 2016
  16. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    is there any new progress available about Google Speech API connection with unity3d. phil_g provided code missing lots of things.
     
  17. theylovegames

    theylovegames

    Joined:
    Aug 18, 2012
    Posts:
    176
    Speech Detection and Speech Synthesis support Windows and Mac for WebGL, Editor, and Standalone.
     
  18. dttngan91

    dttngan91

    Joined:
    Nov 21, 2013
    Posts:
    80
    Hi guys,
    I am looking for a speech recognition offline on mobile platform? Any suggestion?
    Is it possible to implement the MFCC and DTW algorithms to tackle this issue?
     
    taguados likes this.