Esempio n. 1
0
        /// <summary>
        /// This funtion makes API call to get SMS
        /// </summary>
        public RecognitionObj.RootObject speechToTextCustom(string mimeData,
                                                            string XspeechContext,
                                                            string XArgs,
                                                            string SpeechFilePath,
                                                            string xdictionaryContent,
                                                            string xgrammerContent)
        {
            APIRequest apiRequest = new APIRequest("speechToTextCustom");

            string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");

            apiRequest.accept = "application/json";
            apiRequest.addHeaders("Content-Language", "en-us");
            apiRequest.addHeaders("X-Arg", XArgs);
            apiRequest.contentType = "multipart/x-srgs-audio; " + "boundary=" + boundary;
            apiRequest.accept      = "application/json";
            apiRequest.binaryData  = getTotalByte(boundary, xdictionaryContent, SpeechFilePath, xgrammerContent);


            if (apiService.post(apiRequest))
            {
                RecognitionObj robj = new RecognitionObj();
                return(robj.deserializeRecognition(apiService.apiResponse.getResponseData()));
            }

            throw new Exception(apiService.errorResponse);
        }
Esempio n. 2
0
        /// <summary>
        /// This funtion makes API call to get SMS
        /// </summary>
        public RecognitionObj.RootObject speechToText(string parXspeechContext,
                                                      string parXArgs,
                                                      string parSpeechFilePath,
                                                      bool parChunked)
        {
            var          audioFileStream = new FileStream(parSpeechFilePath, FileMode.Open, FileAccess.Read);
            BinaryReader reader          = new BinaryReader(audioFileStream);

            byte[] binaryData = reader.ReadBytes((int)audioFileStream.Length);
            reader.Close();
            audioFileStream.Close();

            if (binaryData.Length > 0)
            {
                APIRequest apiRequest = new APIRequest("speechToText");

                apiRequest.accept = "application/json";
                apiRequest.addHeaders("X-SpeechContext", parXspeechContext);
                apiRequest.addHeaders("X-Arg", parXArgs);
                apiRequest.contentType = "audio/wav";
                apiRequest.accept      = "application/json";
                apiRequest.SendChunked = parChunked;
                apiRequest.binaryData  = binaryData;

                if (apiService.post(apiRequest))
                {
                    RecognitionObj robj = new RecognitionObj();
                    return(robj.deserializeRecognition(apiService.apiResponse.getResponseData()));
                }
                throw new Exception(apiService.errorResponse);
            }
            throw new Exception("No audio data.");
        }
Esempio n. 3
0
        /// <summary>
        /// This funtion makes API call to get SMS
        /// </summary>
        public RecognitionObj.RootObject speechToText(string parXspeechContext,
                                                        string parXArgs,
                                                        string parSpeechFilePath,
                                                        bool parChunked)
        {
            var audioFileStream = new FileStream(parSpeechFilePath, FileMode.Open, FileAccess.Read);
            BinaryReader reader = new BinaryReader(audioFileStream);
            byte[] binaryData = reader.ReadBytes((int)audioFileStream.Length);
            reader.Close();
            audioFileStream.Close();

            if (binaryData.Length > 0)
            {
                APIRequest apiRequest = new APIRequest("speechToText");

                apiRequest.accept = "application/json";
                apiRequest.addHeaders("X-SpeechContext", parXspeechContext);
                apiRequest.addHeaders("X-Arg", parXArgs);
                apiRequest.contentType = "audio/wav";
                apiRequest.accept = "application/json";
                apiRequest.SendChunked = parChunked;
                apiRequest.binaryData = binaryData;

                if (apiService.post(apiRequest))
                {
                    RecognitionObj robj = new RecognitionObj();
                    return robj.deserializeRecognition(apiService.apiResponse.getResponseData());
                }
                throw new Exception(apiService.errorResponse);
            }
            throw new Exception("No audio data.");
        }
Esempio n. 4
0
        /// <summary>
        /// This funtion makes API call to get SMS
        /// </summary>
        public RecognitionObj.RootObject speechToTextCustom(string mimeData,
                                                            string XspeechContext,
                                                            string XArgs,
                                                            string SpeechFilePath,
                                                            string xdictionaryContent,
                                                            string xgrammerContent)
        {
            APIRequest apiRequest = new APIRequest("speechToTextCustom");

            string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");

            apiRequest.accept = "application/json";
            apiRequest.addHeaders("Content-Language", "en-us");
            apiRequest.addHeaders("X-Arg", XArgs);
            apiRequest.contentType = "multipart/x-srgs-audio; " + "boundary=" + boundary;
            apiRequest.accept = "application/json";
            apiRequest.binaryData = getTotalByte(boundary, xdictionaryContent, SpeechFilePath, xgrammerContent);

            if (apiService.post(apiRequest))
            {
                RecognitionObj robj = new RecognitionObj();
                return robj.deserializeRecognition(apiService.apiResponse.getResponseData());
            }

            throw new Exception(apiService.errorResponse);
        }