/// <summary>
 /// Every change in field to recognize inkoves method to recognize in services.
 /// </summary>
 /// <param name="textToRecognition">Valid text from TextBox</param>
 private void InvokeRecognition(string textToRecognition)
 {
     try
     {
         ResultLanguage = _recognizeService.Recognize(textToRecognition);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Recognition issue", MessageBoxButton.OK, MessageBoxImage.Exclamation);
     }
 }
Exemplo n.º 2
0
        public async Task <JsonResult> Upload(int questionId, HttpPostedFileBase blob)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //  Запускаем разпозавание в новом потоке
                    Task <int> task1 = new Task <int>(() => _recognizeService.Recognize(blob.InputStream));
                    task1.Start();
                    int selectedOption = await task1;

                    //  если текст распознался, то сохраняем ответ
                    if (selectedOption > 0)
                    {
                        //  находим вопрос
                        Question question = await _questionService.Get(questionId);

                        if (question != null)
                        {
                            //  выбираем опцию по порядковому номеру
                            Option op = question.Options.ElementAtOrDefault(selectedOption - 1);
                            if (op != null)
                            {
                                //  переводим каретку на начало потока и приводим поток в массив байтов
                                blob.InputStream.Seek(0, SeekOrigin.Begin);
                                MemoryStream ms = new MemoryStream();
                                blob.InputStream.CopyTo(ms);

                                Result result = new Result()
                                {
                                    Voice    = ms.ToArray(),
                                    OptionId = op.Id
                                };
                                await _resultService.Create(result);

                                return(Json(new { success = true, selectedOption = selectedOption, isLastQuestion = await isLastQuestion(questionId) }));
                            }
                        }
                    }
                }
                catch (Exception e) {
                    return(Json(new { success = false, message = e.Message + " " + e.InnerException?.Message }));
                }
            }
            return(Json(new { success = false }));
        }