static void TestICibaClient() { HttpClientICiba iCibaClient = new HttpClientICiba(); String[] wordArr = new String[] { "aaabbbcccddd", "capacity", "buffer", "client" }; foreach (String eachWord in wordArr) { Console.WriteLine(iCibaClient.DownloadAudio(eachWord)); } }
static void DownloadWordList(String listFileName, String dirName) { if (!File.Exists(listFileName)) { throw new Exception("Cannot find given wordlist"); } if (!Path.IsPathRooted(dirName)) { dirName = Path.GetFullPath(dirName); } if (Directory.Exists(dirName)) { Directory.Delete(dirName, true); } Directory.CreateDirectory(dirName); using (StreamReader listReader = new StreamReader(listFileName)) { Int32 wordIdx = 0; String wordStr = String.Empty; String fileName = String.Empty; HttpClientICiba iCibaClient = new HttpClientICiba(); do { wordStr = listReader.ReadLine(); if (null == wordStr) { wordStr = String.Empty; } wordStr = wordStr.Trim(); if (wordStr.Length > 0 && wordStr.IndexOf(' ') < 0) { ++wordIdx; fileName = String.Format("{0}_{1}.mp3", wordIdx.ToString("0000"), wordStr); fileName = Path.Combine(dirName, fileName); Console.WriteLine(iCibaClient.DownloadAudio(wordStr, fileName)); } } while (wordStr.Length > 0); listReader.Close(); } }
private Boolean GenerateMp3(WindowParams wndParams, BackgroundWorker bgWorker, out Exception exception) { Boolean status = true; String[] wordArr = null; List <String> mp3FileList = null; HttpClientICiba iCibaClt = null; AudioJoinerLameExe audioJoiner = null; String tempDir = Environment.CurrentDirectory; String wordMp3TempDir = System.IO.Path.Combine(tempDir, "WordsAudio"); String audioJoinTempDir = System.IO.Path.Combine(tempDir, "JoinDir"); exception = null; try { Int32 wordIdx = 0; iCibaClt = new HttpClientICiba(); wordArr = wndParams.WordArray; mp3FileList = new List <String>(); Directory.CreateDirectory(wordMp3TempDir); for (Int32 i = 0; i < wordArr.Length; ++i) { String singleWord = wordArr[i]; if (!String.IsNullOrEmpty(singleWord)) { String wordMp3 = System.IO.Path.Combine(wordMp3TempDir, String.Format("{0}_{1}.mp3", wordIdx.ToString("0000"), singleWord)); wordMp3 = iCibaClt.DownloadAudio(singleWord, wordMp3); if (!String.IsNullOrEmpty(wordMp3)) { mp3FileList.Add(wordMp3); ++wordIdx; } if (null != bgWorker) { bgWorker.ReportProgress(i * 90 / wordArr.Length); } } } audioJoiner = new AudioJoinerLameExe(); audioJoiner.TempDir = audioJoinTempDir; if (!String.IsNullOrEmpty(wndParams.LameFilePath)) { audioJoiner.LameFilePath = wndParams.LameFilePath; } audioJoiner.JoinAudio(mp3FileList, wndParams.FinalMp3File); if (null != bgWorker) { bgWorker.ReportProgress(100); } } catch (Exception ex) { exception = ex; status = false; } finally { if (status) { Directory.Delete(wordMp3TempDir, true); Directory.Delete(audioJoinTempDir, true); } } return(status); }