private void PlayButton_Click(object sender, RoutedEventArgs e) { TTSWord ttsWord = WordList.SelectedItem as TTSWord; mediaPlayer.Open(new Uri(ttsWord.AudioFileName)); mediaPlayer.MediaEnded += delegate { mediaPlayer.Close(); }; mediaPlayer.Play(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); string path = TTSWord.GetBaseDirectory(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } }
private void DownloadButton_Click(object sender, RoutedEventArgs e) { String word = WordInput.Text; int type = (AmericanEnglishRadioButton.IsChecked == true) ? 2 : 1; TTSWord ttsWord = new TTSWord(word, type); WordList.Items.Add(ttsWord); WordInput.Clear(); TTSClient.Download(ttsWord, this.DownloadFinished); }
public static void Download(TTSWord word, DownloadFinished downloadFinished) { WebClient client = new WebClient(); client.Headers["Accept"] = "*/*"; client.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/70.0.3538.110 Safari/537.36"; Uri wordUri = new Uri(String.Format("http://dict.youdao.com/dictvoice?audio={0}&type={1}", word.Word, word.Type)); try { client.DownloadFile(wordUri, word.AudioFileName); downloadFinished(word, 1); } catch (Exception ex) { downloadFinished(word, 2); } }
public TTSWord(String word, int type) { Word = word; Type = type; AudioFileName = Path.Combine(TTSWord.GetBaseDirectory(), String.Format("{0}_{1}.mp3", this.Word, this.TypeDesc)); }
public void DownloadFinished(TTSWord word, int result) { word.Status = result; WordList.Items.Refresh(); }
private void DownloadAgainButton_Click(object sender, RoutedEventArgs e) { TTSWord ttsWord = WordList.SelectedItem as TTSWord; TTSClient.Download(ttsWord, this.DownloadFinished); }