Пример #1
0
        public void TestMonitor()
        {
            using var listener = new SpeechListener();
            using var monitor  = new AudioBufferRecorder();

            listener.SpeechStarted += (sender, eventArgs) =>
                                      log.Information("Speech started");
            listener.SpeechEnded += (sender, e) =>
            {
                log.Information($"Speech ended. Duration: {e.Span}");
                var data = monitor.GetTimeframe(e.EndTime, e.Span);

                log.Information("Playing back...");
                listener.Pause();
                PlayPCM(data, monitor.WaveFormat);
                listener.Resume();
                log.Information("Playback finished.");
            };

            monitor.BeginRecording();
            listener.BeginListen();

            log.Information("Speak. Press any key to exit.");
            Console.ReadKey();
        }
Пример #2
0
        private static Task InitializeSpeechListener(
            IPredictionRaportingService predictionRaportingService,
            ILanaActionService lanaActionService,
            CancellationTokenSource cts)
        {
            var predictionListeners   = InitializePredictionListeners();
            var actions               = lanaActionService.GetAll();
            var speechGrammarProvider = new SpeechGrammarProvider(actions);
            var _speechListener       = new SpeechListener(
                predictionRaportingService,
                predictionListeners,
                speechGrammarProvider
                );

            return(Task.Run(() => _speechListener.Run(cts)));
        }
Пример #3
0
    //  NEW START FUNCTION FOR THE WEBSOCKIFY VERSION

    IEnumerator Start()
    {
        _patient  = this.gameObject;
        _listener = GetComponent <SpeechListener> ();
        yield return(new WaitForSeconds(2));

//		firstName = "iOSuser";
//		lastName = System.DateTime.Now.ToString("yyyyMMddHHmmss");
        try {
            //mySocket = new WebSocket(new Uri(Host)); // Connect socket on startup

            //mySocket = new WebSocket(new Uri(Host),['binary', 'base64']); // Base template
            //mySocket = new WebSocket("ws://localhost:27016", ["base64"]); // Tried this
            //mySocket = new WebSocket(new Uri(Host), ("binary")); // Tried This - says WebSocket constructor does not take two arguments


            //socketReady = true;
        }
        catch (Exception e) {
            Debug.Log("Socket error: " + e);
            reply = "Socket error: " + e;
            error = true;
        }
    }
Пример #4
0
    public override void OnInspectorGUI()
    {
        SpeechListener speechListenerTarget = target as SpeechListener;

        if (Application.isPlaying)
        {
            string info = "Impossible d'éditer les paramètres pendant l'utilisation.\r\n\r\nNom de SpeechListener : " + speechListenerTarget.listenerName + "\r\n\r\n-Commandes vocales :\r\n";

            info += "\r\n1) Commandes \"évènement\" :\r\n";
            foreach (string str in speechListenerTarget.eventsCommands)
            {
                info += "\t- " + str + "\r\n";
            }

            info += "\r\n2) Commandes personnalisées :\r\n";
            foreach (string str in speechListenerTarget.linkedCommands)
            {
                info += "\t- " + str + "\r\n";
            }

            GUILayout.Label(info, EditorStyles.helpBox);

            return;
        }

        base.OnInspectorGUI();

        #region Events

        if (speechListenerTarget.linkedToEvents != null)
        {
            UnityEvent[] eventsBuffer = speechListenerTarget.events;
            UnityEvent[] newEvents    = new UnityEvent[speechListenerTarget.linkedToEvents.Length];

            if (eventsBuffer == null)
            {
                for (int i = 0; i < newEvents.Length; i++)
                {
                    newEvents[i] = new UnityEvent();
                }
                speechListenerTarget.events = newEvents;
            }
            else
            {
                if (eventsBuffer.Length != newEvents.Length)
                {
                    int size = Mathf.Min(newEvents.Length, eventsBuffer.Length);
                    for (int i = 0; i < size; i++)
                    {
                        newEvents[i] = eventsBuffer[i];
                    }
                    for (int i = size; i < newEvents.Length; i++)
                    {
                        newEvents[i] = new UnityEvent();
                    }

                    speechListenerTarget.events = newEvents;
                }
            }
        }
        else
        {
            speechListenerTarget.events = null;
        }

        #endregion

        #region Add command

        GUILayout.Label("Ajout de commandes", EditorStyles.boldLabel);

        m_command = GUILayout.TextArea(m_command);
        if (m_command.Length == 0)
        {
            return;
        }

        string[] linkedCommands = speechListenerTarget.linkedToFunction;
        if (linkedCommands != null)
        {
            foreach (string linkedCommand in linkedCommands)
            {
                if (linkedCommand.Equals(m_command))
                {
                    return;
                }
            }
        }

        if (GUILayout.Button("Ajouter commande"))
        {
            MonoScript monoscript = MonoScript.FromMonoBehaviour(speechListenerTarget);
            string     path       = AssetDatabase.GetAssetPath(monoscript);

            string scriptText = File.ReadAllText(path);
            int    i;
            for (i = scriptText.Length - 1; i >= 0; i--)
            {
                if (scriptText[i] == '}')
                {
                    break;
                }
            }

            if (i < 0)
            {
                Debug.LogError("Erreur, le fichier est incorrect !");
                return;
            }

            string[] newLinkedCommands;
            if (linkedCommands == null)
            {
                newLinkedCommands = new string[1];
            }
            else
            {
                newLinkedCommands = new string[linkedCommands.Length + 1];
            }
            int j;
            for (j = 0; j < linkedCommands.Length; j++)
            {
                newLinkedCommands[j] = linkedCommands[j];
            }
            newLinkedCommands[j] = m_command;
            speechListenerTarget.linkedToFunction = newLinkedCommands;

            string functionToAppend = FormatForFunction(m_command); //"_"
            functionToAppend = "SpeechRecog_" + functionToAppend + " ()";
            string completeFunctonToAppend = "\r\n\tpublic void " + functionToAppend + "\r\n\t{\r\n\t\tDebug.Log(\"" + m_command + " (default test display)\");\r\n\t}\r\n\t\r\n";

            scriptText = scriptText.Insert(i, completeFunctonToAppend);

            File.WriteAllText(path, scriptText);
        }
        #endregion
    }