private string CatchVoiceAndReturnVocieName(Vocabulary vocabulary) { string template = @"http://www.linguatec.de/onlineservices/vrs15_getmp3?text={0}&voiceName=Tom&speakSpeed=100&speakPith=100&speakVolume=100"; var word = vocabulary.Word; var url = string.Format(template, Uri.EscapeDataString(word)); WebClient wc = new WebClient(); wc.Headers["Host"] = "www.linguatec.de"; wc.Headers["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0"; wc.Headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; wc.Headers["Accept-Language"] = "zh-TW,zh;q=0.8,en-US;q=0.5,en;q=0.3"; wc.Headers["Referer"] = "http://www.linguatec.de/products/tts/voice_reader/vrs15demo"; var script = wc.DownloadString(url); var pattern = @"<audio>(?<Url>.+?)</audio>"; var filePath = Regex.Match(script, pattern).Groups["Url"].Value; if (!string.IsNullOrEmpty(filePath)) { //download var foldPath = Path.Combine(AppHelper.GetAssemblyPath(), "Mp3"); if (!Directory.Exists(foldPath)) { Directory.CreateDirectory(foldPath); } var savedFilePath = Path.Combine(foldPath, Path.GetFileName(filePath)); wc.DownloadFile(filePath, savedFilePath); //return name return Path.GetFileName(filePath); } return ""; }
private void UpdateDbVoiceInfo(Vocabulary vocabulary, string voiceName) { vocabulary.VoiceName = voiceName; vocabulary.IsCatchVoice = true; }
private void UpdateDbTryCatchVoiceCount(Vocabulary vocabulary) { vocabulary.TryToCatchVoiceCount++; }
private void UpdateVocabularyInfo(Vocabulary vocabulary, InfoPoco infoPoco) { vocabulary.Phonetic = infoPoco.Phonetic; vocabulary.Description = infoPoco.Description; vocabulary.IsCatchInfo = true; }
private Guid InsertDbGetId(string fileName, string[] txt) { var db = this.Db; var m = new Master { Name = fileName, CreatedDateTime = AppHelper.GetNow(), Id = Guid.NewGuid() }; var relArr = new List<MasterVocabularyRel>(); //find the existed items var existedItems = db.Vocabularies .Where(a => txt.Contains(a.Word)) .ToList(); foreach (var item in existedItems) { var r = new MasterVocabularyRel { Id = Guid.NewGuid(), Master = m, Vocabular = item, }; relArr.Add(r); } //process not existed items var notExistedItems = txt.Where(a => !existedItems.Select(b => b.Word).Contains(a)); foreach (var item in notExistedItems) { var v = new Vocabulary { Id = Guid.NewGuid(), CreatedDateTime = AppHelper.GetNow(), Word = item, }; var r = new MasterVocabularyRel { Id = Guid.NewGuid(), Master = m, Vocabular = v, }; relArr.Add(r); } //put number int index = 0; foreach (var item in txt) { var o = relArr.FirstOrDefault(a => a.Vocabular.Word == item); if (o == null) continue; o.Sort = index; index++; } db.MasterVocabularyRels.AddRange(relArr); db.SaveChanges(); return m.Id; }