コード例 #1
0
        private static List <SentenceSaveInfo> GetSentenceSaveInfos(EnglishWordTranslationData wordData)
        {
            List <SentenceSaveInfo> sentenceSaveInfos = new List <SentenceSaveInfo>();

            foreach (var sentenceInfo in wordData.Sentences)
            {
                var sentenceSaveInfo = new SentenceSaveInfo()
                {
                    Sentence    = sentenceInfo.Sentence,
                    Translation = sentenceInfo.Translation,
                };
                if (sentenceInfo.EnglishSentenceUri != null && sentenceInfo.EnglishSentenceUri.ToLower().EndsWith(".mp3"))
                {
                    var downloaded = WebResourceDownloadHelper.Download(sentenceInfo.EnglishSentenceUri, CustomPathUtil.SentenceAudioFolder, out var downloadPath);
                    if (downloaded && File.Exists(downloadPath))
                    {
                        sentenceSaveInfo.SentenceFileName = Path.GetFileName(downloadPath);
                    }
                }

                sentenceSaveInfos.Add(sentenceSaveInfo);
            }

            return(sentenceSaveInfos);
        }
コード例 #2
0
 /// <summary>
 /// 设置音频
 /// </summary>
 /// <param name="word"></param>
 /// <param name="wordData"></param>
 private static void SetWordPronounceInfo(WordInfo word, EnglishWordTranslationData wordData)
 {
     if (wordData.UkPronounce != null && !string.IsNullOrEmpty(wordData.UkPronounce.Pronounce))
     {
         word.Pronounce = $"[{wordData.UkPronounce.Pronounce}]";
         //如果音频为空,则下载最新音频
         if (string.IsNullOrEmpty(word.PronounceFileName))
         {
             var downloadSuccess = WebResourceDownloadHelper.Download(wordData.UkPronounce.PronounceUri, CustomPathUtil.WordAudioFolder, out var downloadPath);
             if (downloadSuccess && File.Exists(downloadPath))
             {
                 word.PronounceFileName = Path.GetFileName(downloadPath);
             }
         }
     }
     else if (wordData.UsPronounce != null && !string.IsNullOrEmpty(wordData.UsPronounce.Pronounce))
     {
         word.Pronounce = $"[{wordData.UsPronounce.Pronounce}]";
         //如果音频为空,则下载最新音频
         if (string.IsNullOrEmpty(word.PronounceFileName))
         {
             var downloadSuccess = WebResourceDownloadHelper.Download(wordData.UsPronounce.PronounceUri, CustomPathUtil.WordAudioFolder, out var downloadPath);
             if (downloadSuccess && File.Exists(downloadPath))
             {
                 word.PronounceFileName = Path.GetFileName(downloadPath);
             }
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// 设置音频
        /// </summary>
        /// <param name="wordData"></param>
        /// <param name="pronounceFileName"></param>
        /// <param name="pronounce"></param>
        private static void SetWordPronounceInfo(EnglishWordTranslationData wordData, ref string pronounceFileName, out string pronounce)
        {
            pronounce = string.Empty;
            if (wordData.UkPronounce != null && !string.IsNullOrEmpty(wordData.UkPronounce.Pronounce) && !string.IsNullOrEmpty(wordData.UkPronounce.PronounceUri))
            {
                //如果音频为空,则下载最新音频
                if (string.IsNullOrEmpty(pronounceFileName))
                {
                    var downloadSuccess = WebResourceDownloadHelper.Download(wordData.UkPronounce.PronounceUri, CustomPathUtil.WordAudioFolder, out var downloadPath);
                    if (downloadSuccess && File.Exists(downloadPath))
                    {
                        pronounce         = $"[{wordData.UkPronounce.Pronounce}]";
                        pronounceFileName = Path.GetFileName(downloadPath);
                        return;
                    }
                }
            }
            else if (wordData.UsPronounce != null && !string.IsNullOrEmpty(wordData.UsPronounce.Pronounce) && !string.IsNullOrEmpty(wordData.UsPronounce.PronounceUri))
            {
                //如果音频为空,则下载最新音频
                if (string.IsNullOrEmpty(pronounceFileName))
                {
                    var downloadSuccess = WebResourceDownloadHelper.Download(wordData.UsPronounce.PronounceUri, CustomPathUtil.WordAudioFolder, out var downloadPath);
                    if (downloadSuccess && File.Exists(downloadPath))
                    {
                        pronounce         = $"[{wordData.UsPronounce.Pronounce}]";
                        pronounceFileName = Path.GetFileName(downloadPath);
                        return;
                    }
                }
            }

            if (!string.IsNullOrEmpty(pronounceFileName))
            {
                pronounceFileName = string.Empty;
            }
            if (wordData.UkPronounce != null && !string.IsNullOrEmpty(wordData.UkPronounce.Pronounce))
            {
                pronounce = $"[{wordData.UkPronounce.Pronounce}]";
            }
            else if (wordData.UsPronounce != null && !string.IsNullOrEmpty(wordData.UsPronounce.Pronounce))
            {
                pronounce = $"[{wordData.UsPronounce.Pronounce}]";
            }
        }