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

[Windows] UDP Voice Recognition Server

Discussion in 'Made With Unity' started by ZJP, Mar 4, 2013.

  1. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    A small application that allows voice recognition from a grammar file (grammar.txt who should be in the same directory as the server). The "server" is available in two versions: Win32 and Win64. The application uses the Windows API. It works under Vista 32/64, Win7 32/64 and + (an generic solution whitout needed Windows 10 and Unity 5.5+). For XP, need probably install additional libraries.
    The server is multi-language. It use the default recognition language installed on the system. Of course, the grammar used must be consistent with it.


    Example Grammar.
    Code (csharp):
    1.  
    2. # >> To add a comment
    3. #I >> The IP of the server. 127.0.0.1 if the server is on the same machine as the client.
    4. #P >> UDP Port
    5. #C >> (CLOSE) A "magic" word that stops the server. Of course, it is possible to stop it manually. This word must be present in grammar.
    6. #S >> (START) Enable recognition. Sending of the word via UDP. This word must be present in grammar.
    7. #E >> (END) Disable recognition. Nothing is sent via UDP. This word must be present in grammar.
    8. #N >> Added "Carriage Return" -CHR (13) - at the end of the sent word.
    9. #D >> Display / Show all the blabla in the server console. (Verbose Mode)
    10. #V >> Degree of recognition validation. 0 to 100%. 70 is a good number
    11.  
    Code (csharp):
    1.  
    2. # comment
    3. #C finish
    4. #I 127.0.0.1
    5. #P 26000
    6. #V 70
    7. #N
    8. #S Open a chanel
    9. #E Close the chanel
    10. #V 70
    11. #D
    12.  
    13. Open a chanel
    14. Close the chanel
    15. finish
    16. zero
    17. one
    18. two
    19. three
    20. four
    21. five
    22. six
    23. seven
    24. eight
    25. nine
    26. ten
    27. Patrick
    28. John
    29. Hello
    30. Hi
    31. It's nice
    32. morning
    33. dog
    34. horse
    35. cat
    36. computer
    37. It's a beautiful morning
    38. perfect
    39. opening
    40. closing
    41. Little Red Riding Hood
    42. Unity
    43. The sky is blue and the sun shines
    44. left
    45. right
    46. top
    47. low
    48. jump
    49. shoot
    50. 1984
    51. 2012
    52. 1962
    53. 1504
    54.  
    The Unity UDP source. Stick it on a GameObject

    Code (csharp):
    1.  
    2. // **************************************************************************
    3. //                                                     UDP SPEECH RECOGNITION
    4. // **************************************************************************
    5. using System;
    6. using System.Net;
    7. using System.Text;
    8. using UnityEngine;
    9. using System.Threading;
    10. using System.Net.Sockets;
    11. using System.Collections;
    12.  
    13. public class UDP_RecoServer : MonoBehaviour
    14. {
    15.    Thread receiveThread;
    16.    UdpClient client;
    17.    public int port = 26000; // DEFAULT UDP PORT !!!!! THE QUAKE ONE ;)
    18.    string strReceiveUDP = "";
    19.  
    20.    public void Start()
    21.    {
    22.        Application.runInBackground = true;
    23.        receiveThread = new Thread( new ThreadStart(ReceiveData));
    24.        receiveThread.IsBackground = true;
    25.        receiveThread.Priority     = System.Threading.ThreadPriority.BelowNormal; // AboveNormal, BelowNormal, Normal, Highest, Lowest, Normal
    26.        receiveThread.Start();
    27.    }
    28.  
    29.    private  void ReceiveData()
    30.    {
    31.        client = new UdpClient(port);
    32.        while (true)
    33.        {
    34.            try
    35.            {
    36.                IPEndPoint anyIP = new IPEndPoint(IPAddress.Broadcast, port);
    37.                byte[] data = client.Receive(ref anyIP);
    38.                strReceiveUDP = Encoding.UTF8.GetString(data);
    39.                // **********************************************************
    40.                Action(strReceiveUDP);
    41.                // **********************************************************
    42.            }
    43.            catch (Exception err)
    44.            {
    45.                print(err.ToString());
    46.            }
    47.        }
    48.    }
    49.  
    50.    public void Action(string recoReceive)
    51.    {
    52.        Debug.Log(recoReceive);
    53.        if (recoReceive == "bonjour") Debug.Log("J'ai recu un bonjour du serveur");
    54.        // etc etc etc ...
    55.    }
    56.  
    57.    void OnDisable()
    58.    {
    59.        if ( receiveThread != null) receiveThread.Abort();
    60.        client.Close();
    61.    }
    62. }
    63. // **************************************************************************
    64. //                                                     UDP SPEECH RECOGNITION
    65. // **************************************************************************
    66.  
    67.  
    68.  


    Voice Server source. Originaly made with Visual Studio 2010, but the Solution can by open with MonoDevelop and works fine. :cool:

    Code (csharp):
    1.  
    2. // **************************************************************************************************************************
    3. //                                                                                             RecoServer UDP Version (c) ZJP
    4. // Free Stuff.***************************************************************************************************************
    5. using System;
    6. using System.Collections.Generic;
    7. using System.Text;
    8. using System.IO;
    9. using System.Speech.Recognition;
    10. using System.Net;
    11. using System.Net.Sockets;
    12. using System.Threading;
    13. using System.Diagnostics;
    14.  
    15. namespace RecoServeur
    16. {
    17.    class Program
    18.    {
    19.        public static SpeechRecognitionEngine speechRecognitionEngine;
    20.  
    21.        public static string wordRecognized  = "";
    22.  
    23.         public static string endApp     = "Terminer";
    24.         public static string startReco  = "Ouverture";
    25.         public static string endReco    = "Fermeture";
    26.  
    27.         public static string newLine    = "";
    28.  
    29.        public static string ipServer  = "127.0.0.1";
    30.        public static byte[] data = new byte[512];
    31.        public static int port = 26000;
    32.        public static double validity = 0.70f;
    33.  
    34.         public static Boolean isReco    = false;
    35.         public static Boolean isDisplay = false;
    36.  
    37.        public static Socket server;
    38.        public static IPEndPoint iep;
    39.  
    40.  
    41.        public static void Main(string[] args)
    42.        {
    43.  
    44.            speechRecognitionEngine = new SpeechRecognitionEngine(SpeechRecognitionEngine.InstalledRecognizers()[0]);
    45.            try
    46.            {
    47.                // create the engine
    48.                // hook to events
    49.            //   speechRecognitionEngine.AudioLevelUpdated += new EventHandler<AudioLevelUpdatedEventArgs>(engine_AudioLevelUpdated);
    50.                speechRecognitionEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(engine_SpeechRecognized);
    51.  
    52.                // load dictionary
    53.                try
    54.                {
    55.                    Choices MyVocabulary = new Choices();
    56.  
    57.                    string[] lines = File.ReadAllLines(Environment.CurrentDirectory + "\\grammar.txt");
    58.                    foreach (string line in lines)
    59.                    {
    60.        
    61.                        //reco UDP Port
    62.                        if (line.StartsWith("#P"))
    63.                        {
    64.                            var parts = line.Split(new char[] { ' ' });
    65.                            port = Convert.ToInt32(parts[1]);
    66.                            Console.WriteLine("Port : " + parts[1]);
    67.                            continue;
    68.                        }
    69.                        // Reco IP server
    70.                        if (line.StartsWith("#I"))
    71.                        {
    72.                            var parts = line.Split(new char[] { ' ' });
    73.                            ipServer = parts[1];
    74.                            Console.WriteLine("ipServer : " + parts[1]);
    75.                            continue;
    76.                        }
    77.        
    78.                        // Reco endApp
    79.                        if (line.StartsWith("#C"))
    80.                        {
    81.                            var parts = line.Split(new char[] { ' ' });
    82.                            endApp = parts[1];
    83.                            Console.WriteLine("Close Application Word : " + parts[1]);
    84.                            continue;
    85.                        }
    86.  
    87.                         // Reco startReco
    88.                         if (line.StartsWith("#S"))
    89.                         {
    90.                             var parts = line.Split(new char[] { ' ' });
    91.                             startReco = parts[1];
    92.                             Console.WriteLine("Start Recognition Word : " + parts[1]);
    93.                             continue;
    94.                         }
    95.  
    96.                         // Reco endReco
    97.                         if (line.StartsWith("#E"))
    98.                         {
    99.                             var parts = line.Split(new char[] { ' ' });
    100.                             endReco = parts[1];
    101.                             Console.WriteLine("End Recognition Word : " + parts[1]);
    102.                             continue;
    103.                         }
    104.  
    105.                         // Reco validity
    106.                         if (line.StartsWith("#V"))
    107.                         {
    108.                             var parts = line.Split(new char[] { ' ' });
    109.                             validity = Convert.ToInt32(parts[1]) / 100.0f;
    110.                             Console.WriteLine("Validity : " + parts[1]);
    111.                             continue;
    112.                         }
    113.  
    114.                         // Add NewLine Char after the reco word
    115.                         if (line.StartsWith("#N"))
    116.                         {
    117.                             newLine = "\n";
    118.                             Console.WriteLine("Add NewLine On....");
    119.                             continue;
    120.                         }        
    121.        
    122.                         // Display Reco
    123.                         if (line.StartsWith("#D"))
    124.                         {
    125.                             isDisplay = true;
    126.                             Console.WriteLine("Display (Verbose) on...");
    127.                             continue;
    128.                         }
    129.  
    130.                        // skip comments and empty lines..
    131.                        if (line.StartsWith("#") || line == String.Empty) continue;
    132.  
    133.                         // the recognition grammar
    134.                         MyVocabulary.Add(line);
    135.  
    136.                     } // foreach grammar.txt
    137.                    Grammar wordsList = new Grammar(new GrammarBuilder(MyVocabulary));
    138.                    speechRecognitionEngine.LoadGrammar(wordsList);
    139.                }
    140.                catch (Exception ex)
    141.                {
    142.                    throw ex;
    143.                    System.Environment.Exit(0);
    144.                }
    145.  
    146.                // use the system's default microphone
    147.                speechRecognitionEngine.SetInputToDefaultAudioDevice();
    148.                // start listening
    149.                speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
    150.            }
    151.            catch (Exception ex)
    152.            {
    153.                speechRecognitionEngine.RecognizeAsyncStop();
    154.                 speechRecognitionEngine.Dispose();
    155.  
    156.                 System.Windows.Forms.MessageBox.Show( ex.Message + "\n\nSeem we have an error here : \n\na) Do you have connected a MicroPhone ?! \nb) Have you forgot the 'grammar.txt' file ?!!");
    157.                 // exit
    158.                System.Environment.Exit(0);
    159.            }
    160.            // UDP init
    161.            server  = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    162.            iep = new IPEndPoint(IPAddress.Parse(ipServer), port);
    163.            // Ready
    164.            Console.WriteLine("Reco Server Ready.....");
    165.  
    166.            while (true)
    167.            {
    168.                Thread.Sleep(10);
    169.            }
    170.  
    171.        } // main
    172. /*
    173.        public static  void engine_AudioLevelUpdated(object sender, AudioLevelUpdatedEventArgs e)
    174.        {
    175.            Console.WriteLine(e.AudioLevel);
    176.        }
    177. */
    178.        public static void engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    179.        {
    180.            if (e.Result.Confidence >= validity)
    181.            {
    182.                 wordRecognized = e.Result.Text;
    183.                 // activate the sending reco.
    184.                 if (wordRecognized == startReco)
    185.                 {
    186.                     isReco = true;
    187.                     Console.Title = wordRecognized;
    188.                     Console.BackgroundColor = ConsoleColor.Green;
    189.                     Console.WriteLine("** Sending words is ENABLE **");
    190.                     return;
    191.                 }
    192.                 // de-activate the sending reco.
    193.                 if (wordRecognized == endReco)
    194.                 {
    195.                     isReco = false;
    196.                     Console.Title = wordRecognized;
    197.                     Console.BackgroundColor = ConsoleColor.Red;
    198.                     Console.WriteLine("** Sending words is DISABLE **");
    199.                     return;
    200.                 }
    201.                 // Use the word
    202.                 if (isReco)
    203.                 {
    204.                     Console.Title = wordRecognized;
    205.                    data = Encoding.ASCII.GetBytes(wordRecognized + newLine);
    206.                    server.SendTo(data, iep);
    207.                     if (isDisplay) Console.WriteLine("Sending this : " + wordRecognized);
    208.                    // End of app
    209.                     if (wordRecognized == endApp)
    210.                     {
    211.                         speechRecognitionEngine.RecognizeAsyncStop();
    212.                         speechRecognitionEngine.Dispose();
    213.                         System.Environment.Exit(0);
    214.                     } else return;
    215.                 }
    216.            }
    217.        }
    218.  
    219.    } // Program
    220. } // RecoServeur
    221. // End source
    222. // **************************************************************************************************************************
    223. //                                                                                             RecoServer UDP Version (c) ZJP
    224. // Free Stuff.***************************************************************************************************************
    225.  
    226.  
    ** NEED A MICROPHONE **

    Have fun, ;)

    JP





    Edit :

    Shared Memory - Inter-Process Communication (IPC) - Version


    Code (csharp):
    1.  
    2. // *******************************************************************************************************************************************
    3. //                                                                                             RecoServer Shared Array Version Version (c) ZJP
    4. // Free Stuff.********************************************************************************************************************************
    5. using System;
    6. using System.Collections.Generic;
    7. using System.Text;
    8. using System.IO;
    9. using System.Speech.Recognition;
    10. using System.Threading;
    11. using System.Diagnostics;
    12. // Share Memory Buffer +++++++++++++++++++
    13. // https://sharedmemory.codeplex.com/
    14. using SharedMemory;
    15. // Share Memory Buffer +++++++++++++++++++
    16.  
    17. namespace RecoServeur
    18. {
    19.    class Program
    20.    {
    21.        public static SpeechRecognitionEngine speechRecognitionEngine;
    22.  
    23.        public static string wordRecognized  = "";
    24.        public static string[] ListOfWord;
    25.        public static int nbWord = 0;
    26.        public static bool SendWordIndex = false;
    27.  
    28.        // Share Memory Buffer +++++++++++++++++++
    29.        public static SharedArray<Byte> serverIPC;
    30.        public static byte[] data = new byte[256];
    31.        // Share Memory Buffer +++++++++++++++++++
    32.  
    33.        public static void Main(string[] args)   {
    34.  
    35.            speechRecognitionEngine = new SpeechRecognitionEngine(SpeechRecognitionEngine.InstalledRecognizers()[0]);
    36.            try   {
    37.                // create the engine and  hook to events
    38.                speechRecognitionEngine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(engine_SpeechRecognized);
    39.  
    40.                // load dictionary
    41.                try   {
    42.                    Choices MyVocabulary = new Choices();
    43.                    ListOfWord = new string[256];
    44.                    string[] lines = File.ReadAllLines(Environment.CurrentDirectory + "\\grammar.txt");
    45.                    foreach (string line in lines) {
    46.                        if (line.StartsWith("#INDEX")){
    47.                            SendWordIndex = true;
    48.                            continue;
    49.                        }
    50.                        if (line.StartsWith("#") || line == String.Empty) continue;
    51.  
    52.                        // the recognition grammar
    53.                        MyVocabulary.Add(line);
    54.                        ListOfWord[nbWord] = line;
    55.                        nbWord++;
    56.  
    57.                    } // foreach grammar.txt
    58.                    Grammar wordsList = new Grammar(new GrammarBuilder(MyVocabulary));
    59.                    speechRecognitionEngine.LoadGrammar(wordsList);
    60.                }
    61.                catch (Exception ex){
    62.                    throw ex;
    63.                    System.Environment.Exit(0);
    64.                }
    65.  
    66.                // use the system's default microphone
    67.                speechRecognitionEngine.SetInputToDefaultAudioDevice();
    68.                // start listening
    69.                speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
    70.            }
    71.            catch (Exception ex) {
    72.                speechRecognitionEngine.RecognizeAsyncStop();
    73.                speechRecognitionEngine.Dispose();
    74.  
    75.                System.Windows.Forms.MessageBox.Show( ex.Message + "\n\nSeem we have an error here : \n\na) Do you have connected a MicroPhone ?! \nb) Have you forgot the 'grammar.txt' file ?!!");
    76.                // exit
    77.                System.Environment.Exit(0);
    78.            }
    79.  
    80.            // Share Memory Buffer +++++++++++++++++++++++++++++++++++
    81.            serverIPC = new SharedArray<byte>("WordSharedArray", 256);
    82.            serverIPC[0] = 0; // No Word in the buffer !!!
    83.            // Share Memory Buffer +++++++++++++++++++++++++++++++++++
    84.  
    85.            // Ready
    86.            Console.BackgroundColor = ConsoleColor.Red;
    87.            Console.WriteLine("Reco Server Ready.....");
    88.            Console.Title = "Reco Server Ready.....";
    89.            Console.BackgroundColor = ConsoleColor.Black;
    90.  
    91.            while (true) {
    92.                Thread.Sleep(10);
    93.            }
    94.  
    95.        } // main
    96.  
    97.        public static void engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) {
    98.            if (e.Result.Confidence >= 0.70f) {
    99.                wordRecognized = e.Result.Text;
    100.                Console.WriteLine ("Sending : " + wordRecognized);
    101.                Console.Title = wordRecognized;
    102.                if (SendWordIndex) {
    103.                    // Put the Word index in the Shared array ++++++++++++++++++++++++++++++++++++++++++
    104.                    serverIPC[0] = 0;
    105.                    for (int i = 0; i < nbWord; i++) {  
    106.                        if (ListOfWord[i] == wordRecognized)
    107.                        {
    108.                            serverIPC[0] = (Byte)(i + 1); // New Word index in the Buffer !!!
    109.                            return;
    110.                        }
    111.                    }
    112.                    // Put the Word index in the Shared array ++++++++++++++++++++++++++++++++++++++++++
    113.                } else {
    114.                    // Put the Word in the Shared array ++++++++++++++++++++++++++++++++++++++++++
    115.                    data = Encoding.ASCII.GetBytes(wordRecognized);
    116.                    for (int i = 0; i < data.Length; i++) {  
    117.                        serverIPC [i + 2] = data[i];
    118.                    }
    119.                    serverIPC[1] = (Byte)data.Length;
    120.                    serverIPC[0] = 1; // New Word in the Buffer !!!
    121.                    // Put the Word in the Shared array ++++++++++++++++++++++++++++++++++++++++++
    122.                }
    123.  
    124.            }
    125.        }
    126.  
    127.    } // Program
    128. } // RecoServeur
    129. // End source
    130. // *******************************************************************************************************************************************
    131. //                                                                                             RecoServer Shared Array Version Version (c) ZJP
    132. // Free Stuff.********************************************************************************************************************************
    133.  
    134.  
    135.  


    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using System.IO;
    6.  
    7. // Share Memory Buffer ++++++++++++++++++++++
    8. // https://sharedmemory.codeplex.com/
    9. // Add 'SharedMemory.dll' in a Plugins folder
    10. using SharedMemory;
    11. // Share Memory Buffer ++++++++++++++++++++++
    12.  
    13. public class WordShared : MonoBehaviour {
    14.  
    15.    SharedArray<byte> clientIPC;
    16.    private bool sArray;
    17.    public bool WordIndexMode = false;
    18.  
    19.  
    20.    void Start () {
    21.  
    22.        Debug.Log("SharedMemory Client");
    23.        sArray = true;
    24.        try  {
    25.            clientIPC = new SharedArray<byte>("WordSharedArray"); // ouverture du buffer
    26.         }
    27.         catch (FileNotFoundException ex) {
    28.            sArray = false;
    29.         }
    30.  
    31.    }
    32.  
    33.    void FixedUpdate()
    34.    {
    35.        if (!sArray) return;
    36.        if (!clientIPC.ShuttingDown)
    37.        {
    38.  
    39.            if (WordIndexMode) {
    40.                if (clientIPC[0] > 0) // New Index Word in the Buffer ???
    41.                {
    42.                    Debug.Log("New Index Word is coming !!! : " + clientIPC[0] );
    43.                    clientIPC[0] = 0; // I got the Index Word. Put a new one.
    44.                    return;
    45.                }
    46.            } else {
    47.                if (clientIPC[0] == 1) // New Word in the Buffer ???
    48.                {
    49.                    // Yes
    50.                    string response = string.Empty;
    51.                    for (int i = 0; i < clientIPC[1]; i++) {
    52.                        response += (char)clientIPC[i + 2];
    53.                    }
    54.                    clientIPC[0] = 0; // I got the Word. Put a new one.
    55.                    Debug.Log("New Word is coming !!! : " + response );
    56.                    return;
    57.                }          
    58.            }
    59.  
    60.        }
    61.    }
    62. }
    63.  
    64.  
    65.  
    66.  
     

    Attached Files:

    Last edited: May 30, 2017
    UltimosJN, roumenf and MJNuchia like this.
  2. ashjack

    ashjack

    Joined:
    Jun 9, 2013
    Posts:
    44
    The instructions on screen didn't really help me. How do I set this up on my game? I am 32 bit.
     
  3. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    a) Launch the RecoServeurX86. Do not forget to set the vocabulary in the grammar.txt file
    b) On Unity3D, put "UDP_RecoServer.cs" on a gameObject
    c) All the recognized words are available in strReceiveUDP >> function ReceiveData()
     
  4. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    722
    hi,

    Do u have any demo scene .
     
  5. lancer

    lancer

    Joined:
    Aug 1, 2013
    Posts:
    231
    Hey ZJP,

    When I run the .exe I get an error that says it is missing the grammar file, but the grammar file is in there and if I run it from the command line it works just fine. Do you have any idea about what is happening there?
     
  6. olop01

    olop01

    Joined:
    Jul 5, 2012
    Posts:
    14
    So I started Unity, added the code to a Game Object, created the grammar.txt, and plugged in my microphone. I changed the port to Port 4.
    After starting RecoServer it said "ready" and I started my game. The console said my IP adress but nothing more happened. No strings were written to the Console and it seemed liek nothing happens (except my Windows Firewall asking for permission to RecoServer which I granted).

    What am I missing?
     
  7. Seriously

    Seriously

    Joined:
    Jun 15, 2013
    Posts:
    9
    Works fine for me using the default port of 26000. Does not work using Port 4.
     
  8. 8volution

    8volution

    Joined:
    Nov 14, 2012
    Posts:
    88
    Is there anything like this for OSX (standalone application)?
     
    KnightRiderGuy likes this.
  9. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Sorry. Win32/64 only.
     
  10. Mystic_nynja

    Mystic_nynja

    Joined:
    Feb 5, 2013
    Posts:
    14
    When I run the service and I speak a word that is in the file I get this error.

    Code (csharp):
    1.  
    2. System.Security.SecurityException: Unable to connect, as no valid crossdomain policy was found
    3.   at System.Net.Sockets.Socket.ReceiveFrom_nochecks_exc (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint remote_end, Boolean throwOnError, System.Int32 error) [0x00000] in <filename unknown>:0
    4.   at System.Net.Sockets.Socket.ReceiveFrom_nochecks (System.Byte[] buf, Int32 offset, Int32 size, SocketFlags flags, System.Net.EndPoint remote_end) [0x00000] in <filename unknown>:0
    5.   at System.Net.Sockets.Socket.ReceiveFrom (System.Byte[] buffer, System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
    6.   at System.Net.Sockets.UdpClient.Receive (System.Net.IPEndPoint remoteEP) [0x00000] in <filename unknown>:0
    7.   at UDP_RecoServer.ReceiveData () [0x00034] in .../UDP_RecoServer.cs:53
    8.  
    On that line of code is:
    Code (csharp):
    1.  
    2. byte[] data = client.Receive(ref anyIP);
    3.  
    I assume it has to do with what port I am using, which I tried both 26000 and 843 (saw this port in another thread)

    All other values in the grammar file are default to what you have on top.

    Any help would be appreciated!

    Thanks
     
  11. kayang

    kayang

    Joined:
    Apr 4, 2013
    Posts:
    1



    I managed to get this work , how do i control a character from here .
    Is there any sample you can share ?
     
  12. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    115
    So I've got this working with the grammar file very well. I'm using all the defaults from the original post.
    However I noticed if you say words from the grammar file in quick succession it only reads the first word.
    For instance if I said "Hello perfect cat", all of which are separate entries in the grammar.txt file, it will only print "Hello".

    Is there any way to adapt this better for string recognition like above, without having to enter every possible phrase in to the grammar.txt?
     
  13. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    This application is based on the Windows API/SDK. This is unfortunately the way it works. :(
     
  14. TerabyteTim

    TerabyteTim

    Joined:
    Oct 20, 2011
    Posts:
    115
    Ouch, that's too bad. Guess I'll have to find a different API for voice recognition.
     
  15. DRProductions

    DRProductions

    Joined:
    Jan 21, 2013
    Posts:
    15
    Sorry to dig up a dead thread, but I have been using this for a little awhile with no issues, and just a few hours ago suddenly it stopped recognizing my voice and an error appears after ending the play session

    NullReferenceException: Object reference not set to an instance of an object
    UDP_RecoServer.OnDisable () (at Assets/VoiceRecognition/UDP_RecoServer.cs:72)

    If im not mistaken that means that there is no value set for client (line 72 refers to client.Close)
    I cant seem to figure out why it would not find a client, I have set the ip's and ports the same, default port and using the ip that is shown in the Debug Console after running the script (this ip is for some reason diferent than 127.0.0.1)

    FIXED: Had to change the port number for some reason
     
    Last edited: Aug 5, 2014
  16. WesleyNasray

    WesleyNasray

    Joined:
    Aug 30, 2014
    Posts:
    1
    It just works!

    I just had to change my Windows system language to english so at least one "recognition system" was available (the server/code crashes on line 26 if there are no "systems" on the collection).

    And I couldn't use SendMessage() on the suggested place, log shows that SendMassage() need to be called on the Main thread; so I called it on Update() and used a bool for triggering the SendMessage() inside Update().

    Is possible to adapt so it runs on Windows Phone 8? I'm going to try this.

    And... Thanks for sharing this work, it's well explained (and works) ;)


    Edit: It worked fine on my Windows 8.1 x64
     
    ZJP likes this.
  17. 4wall

    4wall

    Joined:
    Sep 16, 2014
    Posts:
    73
    Does this require any additional Windows Speech SDK-API downloads-installations? Or should it work with the stock Windows 8 install?
     
  18. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    I don't know. I do not have windows 8.x. Still on W7 :p
     
  19. 4wall

    4wall

    Joined:
    Sep 16, 2014
    Posts:
    73
    Does Speech recognition have to turned on first in order for this to work? What should I see in the Unity console when I speak a word listed in the grammar.txt file?
     
  20. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Yes

    The recognized word.
     
  21. 4wall

    4wall

    Joined:
    Sep 16, 2014
    Posts:
    73
    Thanks!!! Really want to get this to work so would appreciate any troubleshooting steps.
    1- I have edited the grammar.txt file and added a few simple test words, 'Testing', 'Start', Hello'
    2- Speech recognition is turned on, I can see 'Listening'
    3- I launch the RecoServeurX64.exe (from the bin Release folder) making sure my grammar.txt file is in the same folder. I see 'Ready...' in the console window for the app
    4- I launch the Unity IDE(4.6 beta) and attach the Unity script to the main camera
    5- I play Unity, I can see 'MY IP:......' in the console window, but when I speak any of the predefined words, although they are registered by the microphone, nothing happens, nothing appears in the Unity console.
     
  22. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  23. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Got it working!!. One issue, the server only seems to recognize my key words-phrases once.

    What changes do I need to make to the server so that it will recognize keywords-phrases more than once?
     
    jkarian likes this.
  24. jlcra

    jlcra

    Joined:
    Jan 27, 2014
    Posts:
    13
    Has anyone worked this into an an application that they've built as a PC standalone?

    What I've been trying to do is using System.Diagnostics.Process.Start() to run the server (when the Unity scene opens), but it only opens the server for a second and then I get a NullReferenceException error. I can use Process.Start() to open other applications (like notepad), but when I try to open the server.exe it doesn't work. Anyone have any pointers?
     
  25. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Is there a better fix for 'SendMessage() need to be called on the Main thread;' error than use of a boolean in Update()?
     
  26. jlcra

    jlcra

    Joined:
    Jan 27, 2014
    Posts:
    13
    eco_bach -- That's what I wound up using and it seems to work fairly well. There is a short delay before the message is sent, but I think that's from the voice recognizer code/server, and not from using this method of sending a message.
     
  27. ellenrojek

    ellenrojek

    Joined:
    Oct 31, 2014
    Posts:
    1
    Is there any way to adapt this better for string recognition, without having to enter every possible phrase in to the grammar?
    Thank you for your help!
     
  28. TheTSN

    TheTSN

    Joined:
    Nov 12, 2014
    Posts:
    3
    How would I be able to make it pick up a word from my grammar.txt and then a function starts. For example, if i said cat, an image of a cat would appear, but if i said dog a dog would appear.
     
    jcdelz likes this.
  29. UltimosJN

    UltimosJN

    Joined:
    Nov 20, 2014
    Posts:
    1
    Although old, your thread still is a life saver. Thank you very much ^^
     
  30. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    I will try next week to add this library into the project. This should solve most of the disorders with UDP. It will be an extra option.


    Edit :

    Done here...
     
    Last edited: Jan 1, 2015
  31. IreAlMar

    IreAlMar

    Joined:
    Apr 22, 2015
    Posts:
    2
    Awesome! Just thank you for sharing your code! It works perfect.
    Thanks!!
     
    ZJP likes this.
  32. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    You're welcome. ;)
     
  33. IreAlMar

    IreAlMar

    Joined:
    Apr 22, 2015
    Posts:
    2
    Code (CSharp):
    1. private static string outputPath = "RecoServeurX64.exe";      
    2.  
    3.     // Use this for initialization
    4.     void Start () {
    5.         Process foo = new Process();
    6.         foo.StartInfo.FileName = outputPath;
    7.         foo.Start ();
    8.     }
    works fine for me
     
    ZJP likes this.
  34. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  35. Nakaru

    Nakaru

    Joined:
    Feb 25, 2015
    Posts:
    4
    Sorry for dig up a dead thread, but i have a "funny" problem.
    i use your program, but the only word it detect... is the "shutdown" word
    any idea?
     
  36. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  37. Nakaru

    Nakaru

    Joined:
    Feb 25, 2015
    Posts:
    4
    was first i done
     
  38. rp_yoda

    rp_yoda

    Joined:
    Dec 6, 2015
    Posts:
    1
    HI everybody. The server is working well, but now I try to close it...
    Code (CSharp):
    1. private static string outputPath = "RecoServeurX64.exe";    
    2.  
    3. void Start () {
    4.         Process foo = new Process();
    5.         foo.StartInfo.FileName = outputPath;
    6.         foo.Start ();
    7. }
    8.  
    9. void update(){
    10. if (Input.GetKey(KeyCode.Escape))
    11.         {
    12.             foo.Close();
    13.         }
    14. }
    My problem is that I try to make foo.Close() and the server still running
     
  39. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    What about
    Code (csharp):
    1.  
    2. private static string outputPath = "RecoServeurX64.exe";  
    3. private Process foo;
    4.  
    5. void Start ()
    6. {
    7.    foo = new Process();
    8.    foo.StartInfo.FileName = outputPath;
    9.    foo.Start ();
    10. }
    11.  
    12. void update()
    13. {
    14.    if (Input.GetKey(KeyCode.Escape))
    15.    {
    16.      foo.Close(); // foo.Kill()
    17.    }
    18. }
    19.  
    20.  
    21.  
    or
    Code (csharp):
    1.  
    2. System.Diagnostics.Process.Start("taskkill /F /T /IM RecoServeurX64.exe");
    3.  
     
    Last edited: Dec 6, 2015
  40. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
  41. ChuckIes

    ChuckIes

    Joined:
    May 18, 2015
    Posts:
    9
    The program works excellent :) I would use the keyboard emulator version, but it interferes with using my own keyboard. My only complaint is that I can't combine words - for example, I can't put "hello" and "world" as separate entries in grammar.txt and then have it pick up "hello world". I'm not familiar with Microsoft speech recognition, would that even be possible?
     
  42. ashokbugude

    ashokbugude

    Joined:
    Feb 10, 2016
    Posts:
    20
    Its working fine in unity, but getting below error. Could you pls tell how to resolve it

    Error:
    get_isActiveAndEnabled can only be called from the main thread.
    Constructors and field initializers will be executed from the loading thread when loading a scene.
    Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
     
  43. Sharmila

    Sharmila

    Joined:
    Feb 17, 2016
    Posts:
    1
    Hai,
    I'm using windows 8.1 64 bit OS. Can someone help me by telling how to install RecoServerX86?
     
  44. Harlock1980

    Harlock1980

    Joined:
    Sep 22, 2015
    Posts:
    4
    Hi!

    All is working rigth while using local ip address for the Unity project and server (127.0.0.1) but I'm trying to put the server in other coputer of my network (with write/read rigths), changing de IP on grammar.txt, and when I start the Unity project it doesn't work, doesn't write any Debug.Log on Unity console.

    What I'm doing wrong?
     
  45. pan-master

    pan-master

    Joined:
    Nov 11, 2013
    Posts:
    127
    OK. I have a question..... there is windows 10 speech recognision and there is cortana... I want to integrate spech recognision in my Unity app where do I start?
     
  46. EyePD

    EyePD

    Joined:
    Feb 26, 2016
    Posts:
    63
    Last edited: May 26, 2016
  47. jkarian

    jkarian

    Joined:
    Feb 4, 2014
    Posts:
    3
    I'm having the same issue, each word is only recognized once did you figure this out? If so please do share. Thanks a lot!
     
  48. jkarian

    jkarian

    Joined:
    Feb 4, 2014
    Posts:
    3
    I suppose you would need the 64-bit version of Recoserver. To install it run it from the windows command line. First make sure it is in the same folder as the grammar.txt file.
     
  49. FrostweepGames

    FrostweepGames

    Joined:
    Jan 2, 2015
    Posts:
    264
  50. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    245
    In the original post it says that it "maybe" supports win8. So has this been updated to support win8 and maybe win10, or is it still in the same place regarding support of those platforms?