Ejemplo n.º 1
0
        public FileResult Speak(UserLanguages userLanguages, long id, SpeakerDataType type, bool mp3Support)
        {
            byte[] audioBytes = null;
            if (UserLanguages.IsValid(userLanguages) && IdValidator.IsValid(id))
            {
                audioBytes = GetPronunciation(id, type);
            }
            if (audioBytes == null)
            {
                audioBytes = new byte[0];
                LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                    "SpeakerController.Speak. Для типа {0} с идентификатором {1} НЕ найдено произношение!",
                    type, id);
            }

            /*if (!mp3Support) {
             *  var audioConverter = new AudioConverter();
             *  byte[] result = audioConverter.ConvertMp3ToWav(audioBytes);
             *  if (result != null) {
             *      return File(result, "audio/wav");
             *  }
             * }*/

            return(File(audioBytes, "audio/mp3"));
        }
Ejemplo n.º 2
0
 public GroupModel(GroupForUser group,
                   SpeakerDataType speakerDataType,
                   KnowledgeDataType knowledgeDataType,
                   GroupModelOptions options,
                   UserLanguages userLanguages,
                   List <SourceWithTranslation> groupElemsWithTranslations)
     : base(userLanguages, groupElemsWithTranslations)
 {
     SpeakerDataType   = speakerDataType;
     KnowledgeDataType = knowledgeDataType;
     Id        = group.Id;
     GroupName = group.Name;
     _options  = options;
 }
Ejemplo n.º 3
0
        public TrainerModel GetTrainerModel(HttpRequestBase request)
        {
            var model = new TrainerModel(_userLanguages);
            List <UserRepetitionIntervalItem> repetitionIntervalItems =
                _userRepetitionIntervalQuery.GetRepetitionIntervalItems(_userLanguages.From.Id,
                                                                        _userLanguages.To.Id,
                                                                        MAX_COUNT_ITEMS_TO_GET);

            foreach (UserRepetitionIntervalItem repetitionItem in
                     repetitionIntervalItems ?? new List <UserRepetitionIntervalItem>(0))
            {
                var trainerItem = new TrainerItem();

                var userKnowledge = repetitionItem.Data as UserKnowledgeItem;
                if (userKnowledge != null)
                {
                    var dataType = userKnowledge.DataType;
                    //тренируемся на запоминание пользовательских данных
                    SpeakerDataType speakerType = KnowledgeHelper.GetSpeakerType(dataType);
                    var             parsedData  = userKnowledge.ParsedData as SourceWithTranslation;

                    trainerItem.NextTimeToShow        = KnowledgeHelper.ConvertDateTimeToJsTicks(repetitionItem.NextTimeToShow);
                    trainerItem.DataId                = repetitionItem.DataId;
                    trainerItem.DataType              = (int)repetitionItem.DataType;
                    trainerItem.HtmlSource            = OurHtmlHelper.GetSpeakerHtml(parsedData.Source, speakerType);
                    trainerItem.HtmlTranslation       = OurHtmlHelper.GetSpeakerHtml(parsedData.Translation, speakerType);
                    trainerItem.SourceLanguageId      = parsedData.Source.LanguageId;
                    trainerItem.TranslationLanguageId = parsedData.Translation.LanguageId;
                    trainerItem.ImageUrl              = parsedData.HasImage ? GetImageUrl(request, parsedData.Id, dataType) : null;
                }

                if (IdValidator.IsValid(trainerItem.DataId) && trainerItem.HtmlSource != null &&
                    trainerItem.HtmlTranslation != null)
                {
                    //данные такого типа, могут быть представлены
                    model.AddItem(trainerItem);
                }
            }
            return(model);
        }
Ejemplo n.º 4
0
        private static byte[] GetPronunciation(long id, SpeakerDataType type)
        {
            IPronunciationQuery pronunciationQuery = null;

            if (type == SpeakerDataType.Word)
            {
                pronunciationQuery = new WordsQuery();
            }
            else if (type == SpeakerDataType.Sentence)
            {
                pronunciationQuery = new SentencesQuery();
            }
            if (pronunciationQuery == null)
            {
                LoggerWrapper.LogTo(LoggerName.Errors).ErrorFormat(
                    "SpeakerController.GetPronunciation передан некорректный тип {0}", type);
                return(null);
            }
            IPronunciation pronunciationEntity = pronunciationQuery.GetById(id);

            return(pronunciationEntity != null ? pronunciationEntity.Pronunciation : null);
        }
Ejemplo n.º 5
0
        public static string GetSpeakerHtml(PronunciationForUser pronunciationForUser, SpeakerDataType type)
        {
            string sourceText = String.Format("{0}{1}",
                                              pronunciationForUser.HasPronunciation
                                                  ? String.Format(SPEAKER_PATTERN_HTML, pronunciationForUser.Id,
                                                                  (int)type)
                                                  : String.Empty, pronunciationForUser.Text);

            return(sourceText);
        }