Пример #1
0
        private void NetworkResponseEventHandler(NetworkResponse response)
        {
            if (GCSpeechRecognition.Instance.isFullDebugLogIfError)
            {
                Debug.Log(response.error + "\n" + response.response);
            }

            if (!string.IsNullOrEmpty(response.error))
            {
                if (RecognitionFailedEvent != null)
                {
                    RecognitionFailedEvent(response.error, response.netPacketIndex);
                }
            }
            else
            {
                if (response.response.Contains("error"))
                {
                    if (RecognitionFailedEvent != null)
                    {
                        RecognitionFailedEvent(response.response, response.netPacketIndex);
                    }
                }
                else if (response.response.Contains("results"))
                {
                    if (RecognitionSuccessEvent != null)
                    {
                        RecognitionSuccessEvent(JsonUtility.FromJson <RecognitionResponse>(response.response), response.netPacketIndex);
                    }
                }
                else if (response.response.Contains("{}"))
                {
                    if (RecognitionFailedEvent != null)
                    {
                        RecognitionFailedEvent("Any Words Not Detected!", response.netPacketIndex);
                    }
                }
                else
                {
                    if (RecognitionFailedEvent != null)
                    {
                        RecognitionFailedEvent("Process Parse Response failed with error: " + response.response, response.netPacketIndex);
                    }
                }
            }
        }
Пример #2
0
        public void Update()
        {
            for (int i = 0; i < _networkRequests.Count; i++)
            {
                if (_networkRequests[i].request.isDone)
                {
                    NetworkResponse response = new NetworkResponse(_networkRequests[i].request.downloadHandler.text,
                                                                   _networkRequests[i].request.error,
                                                                   _networkRequests[i].netPacketIndex);

                    _networkResponses.Add(response);

                    if (NetworkResponseEvent != null)
                    {
                        NetworkResponseEvent(response);
                    }

                    _networkRequests.RemoveAt(i--);
                }
            }
        }
Пример #3
0
        private void NetworkResponseEventHandler(NetworkResponse response)
        {
            if (response.HasError() && GCSpeechRecognition.Instance.isFullDebugLogIfError)
            {
                Debug.LogError(response.GetFullLog());
            }

            if (response.Parameters.Length > 0)
            {
                Enumerators.ApiType apiType = (Enumerators.ApiType)response.Parameters[0];

                switch (apiType)
                {
                case Enumerators.ApiType.RECOGNIZE:
                {
                    if (response.HasError())
                    {
#if !NET_2_0 && !NET_2_0_SUBSET
                        RecognizeFailedEvent?.Invoke(response.GetFullLog());
#else
                        if (RecognizeFailedEvent != null)
                        {
                            RecognizeFailedEvent(response.GetFullLog());
                        }
#endif
                    }
                    else
                    {
#if !NET_2_0 && !NET_2_0_SUBSET
                        RecognizeSuccessEvent?.Invoke(JsonConvert.DeserializeObject <RecognitionResponse>(response.Response));
#else
                        if (RecognizeSuccessEvent != null)
                        {
                            RecognizeSuccessEvent(JsonConvert.DeserializeObject <RecognitionResponse>(response.Response));
                        }
#endif
                    }
                }
                break;

                case Enumerators.ApiType.LONG_RUNNING_RECOGNIZE:
                {
                    if (response.HasError())
                    {
#if !NET_2_0 && !NET_2_0_SUBSET
                        LongRunningRecognizeFailedEvent?.Invoke(response.GetFullLog());
#else
                        if (LongRunningRecognizeFailedEvent != null)
                        {
                            LongRunningRecognizeFailedEvent(response.GetFullLog());
                        }
#endif
                    }
                    else
                    {
#if !NET_2_0 && !NET_2_0_SUBSET
                        LongRunningRecognizeSuccessEvent?.Invoke(JsonConvert.DeserializeObject <Operation>(response.Response));
#else
                        if (LongRunningRecognizeSuccessEvent != null)
                        {
                            LongRunningRecognizeSuccessEvent(JsonConvert.DeserializeObject <Operation>(response.Response));
                        }
#endif
                    }
                }
                break;

                case Enumerators.ApiType.LIST_OPERATIONS:
                {
                    if (response.HasError())
                    {
#if !NET_2_0 && !NET_2_0_SUBSET
                        ListOperationsFailedEvent?.Invoke(response.GetFullLog());
#else
                        if (ListOperationsFailedEvent != null)
                        {
                            ListOperationsFailedEvent(response.GetFullLog());
                        }
#endif
                    }
                    else
                    {
#if !NET_2_0 && !NET_2_0_SUBSET
                        ListOperationsSuccessEvent?.Invoke(JsonConvert.DeserializeObject <ListOperationsResponse>(response.Response));
#else
                        if (ListOperationsSuccessEvent != null)
                        {
                            ListOperationsSuccessEvent(JsonConvert.DeserializeObject <ListOperationsResponse>(response.Response));
                        }
#endif
                    }
                }
                break;

                case Enumerators.ApiType.OPERATION:
                {
                    if (response.HasError())
                    {
#if !NET_2_0 && !NET_2_0_SUBSET
                        GetOperationFailedEvent?.Invoke(response.GetFullLog());
#else
                        if (GetOperationFailedEvent != null)
                        {
                            GetOperationFailedEvent(response.GetFullLog());
                        }
#endif
                    }
                    else
                    {
#if !NET_2_0 && !NET_2_0_SUBSET
                        GetOperationSuccessEvent?.Invoke(JsonConvert.DeserializeObject <Operation>(response.Response));
#else
                        if (GetOperationSuccessEvent != null)
                        {
                            GetOperationSuccessEvent(JsonConvert.DeserializeObject <Operation>(response.Response));
                        }
#endif
                    }
                }
                break;

                default: break;
                }
            }
        }
        private void NetworkResponseEventHandler(NetworkResponse response)
        {
            if (GCSpeechRecognition.Instance.isFullDebugLogIfError)
            {
                Debug.Log(response.error + "\n" + response.response);
            }

            switch (response.recognitionType)
            {
            case Enumerators.GoogleNetworkType.SPEECH_RECOGNIZE:
            {
                if (response.response.Contains("results"))
                {
                    if (RecognitionSuccessEvent != null)
                    {
                        RecognitionSuccessEvent(JsonUtility.FromJson <RecognitionResponse>(response.response), response.netPacketIndex);
                    }
                }
                else
                {
                    if (NetworkRequestFailedEvent != null)
                    {
                        NetworkRequestFailedEvent(response.response, response.netPacketIndex);
                    }
                }
            }
            break;

            case Enumerators.GoogleNetworkType.SPEECH_LONGRECOGNIZE:
            {
                if (response.response.Contains("name"))
                {
                    if (LongRecognitionSuccessEvent != null)
                    {
                        LongRecognitionSuccessEvent(Newtonsoft.Json.JsonConvert.DeserializeObject <OperationLongRecognizeResponse>(response.response), response.netPacketIndex);
                    }
                }
                else
                {
                    if (NetworkRequestFailedEvent != null)
                    {
                        NetworkRequestFailedEvent(response.response, response.netPacketIndex);
                    }
                }
            }
            break;

            case Enumerators.GoogleNetworkType.GET_OPERATION:
            {
                if (response.response.Contains("name"))
                {
                    if (GetOperationDataSuccessEvent != null)
                    {
                        GetOperationDataSuccessEvent(Newtonsoft.Json.JsonConvert.DeserializeObject <OperationResponse>(response.response), response.netPacketIndex);
                    }
                }
                else
                {
                    if (NetworkRequestFailedEvent != null)
                    {
                        NetworkRequestFailedEvent(response.response, response.netPacketIndex);
                    }
                }
            }
            break;

            default: break;
            }
        }