private void hienthiapi() { DataTable dt = new DataTable(); WS_Service.WS_Service ds = new WS_Service.WS_Service(); dt = ds.DanhSachAPI(); cmbapi.DataSource = dt; cmbapi.ValueMember = "API"; cmbapi.DisplayMember = "API"; }
private void bgwlayvoice_DoWork(object sender, DoWorkEventArgs e) { DataTable dt = new DataTable(); WS_Service.WS_Service ds = new WS_Service.WS_Service(); dt = ds.DanhSachCanRender(); if (dt.Rows.Count > 0) { DataRow r = dt.Rows[0]; string _ngonngu = r["NgonNgu"].ToString(); string _gioitinh = r["GioiTinh"].ToString(); string _noidung = r["NoiDung"].ToString(); string _id = r["ID"].ToString(); #region // thực hiện update đang render WS_Service.WS_Service render = new WS_Service.WS_Service(); render.UpdateDangRender(Guid.Parse(r["ID"].ToString())); #endregion if (!Directory.Exists(txtfloderout.Text + @"\Out\" + r["ID"].ToString())) { Directory.CreateDirectory(txtfloderout.Text + @"\Out\" + r["ID"].ToString()); } XoaFilemp3(txtfloderout.Text + @"\Out"); #region text cat nho string chuoingatcau = @". "; if (_ngonngu == "Japanese") { chuoingatcau = @"。"; } else if (_ngonngu == "Chinese") { chuoingatcau = @"。"; } else { chuoingatcau = @". "; } string temp = chuanHoa(_noidung).Replace(chuoingatcau, "|"); string[] listtext = temp.Split('|'); #region // xử lý bật site lấy voice ChromeOptions options = new ChromeOptions(); // options.AddArgument("headless"); // PropretiesCollection.driver = new ChromeDriver(service,options); PropretiesCollection.driver = new ChromeDriver(options); cl_ReadVoice read = new cl_ReadVoice(); if (radvoiceware.Checked == true) { PropretiesCollection.driver.Navigate().GoToUrl("http://www.voiceware.co.kr/eng/product/product1.php?fbclid=IwAR3uoWfvMJ6g53aNRf6o3WSm8A4fbq3hg7OVjXRD4K43ktPh9SsyP_zDnQ0"); read.selectV2(_ngonngu, ""); } else if (radTTScool.Checked == true) { PropretiesCollection.driver.Navigate().GoToUrl("https://tts.cool/"); read.select_Service(cmbapi.Text); read.select_Sex(_gioitinh); read.selectV2_TTSCool(_ngonngu); } #endregion DataTable _DuLieu = new DataTable(); _DuLieu.Columns.Add("FileVoice", typeof(string)); int k = 1; string _urlvoicecu = ""; string listvoice = ""; for (int row = 0; row < listtext.Length; row++) { #region //DUYET LAY VOICE string url = ""; string text = listtext[row].ToString(); if (text != "") { txtthongbao.Text = "Đang lấy voice id:" + _id + " thứ " + k.ToString() + ":" + text.ToString(); string voicefile = txtfloderout.Text + @"\Out\" + r["ID"].ToString() + @"\" + row.ToString() + ".wav"; string _voice = txtfloderout.Text + @"\Out\" + r["ID"].ToString() + @"\" + row.ToString() + ".mp3"; if (radvoiceware.Checked == true) { if (text.Length >= 200) { url = read.getURLMp3_V2(_urlvoicecu, text.Trim().Substring(0, 199)); _urlvoicecu = url; } else { url = read.getURLMp3_V2(_urlvoicecu, text.Trim()); _urlvoicecu = url; } if (url != "") { downloadFileV2(url, voicefile); } Thread.Sleep(2000); RunFFMPEG fftangmam = new RunFFMPEG(); string voicexulytamam = txtfloderout.Text + @"\Out\" + r["ID"].ToString() + @"\voicexuly" + row.ToString() + ".wav"; string tangam = string.Format(@"-i {0} -filter:a loudnorm {1}", voicefile, voicexulytamam); fftangmam.RunCommand(tangam, true); voicefile = voicexulytamam; } else if (radTTScool.Checked == true) { if (text.Length >= 200) { url = read.getURL_TTSCool(_urlvoicecu, text.Trim().Substring(0, 199)); _urlvoicecu = url; } else { url = read.getURL_TTSCool(_urlvoicecu, text.Trim()); _urlvoicecu = url; } if (url != "") { downloadFileV2_Ex(url, _voice); Thread.Sleep(2000); } voicefile = _voice; } if (File.Exists(voicefile)) { _DuLieu.Rows.Add(voicefile); //if (listvoice == "") //{ // listvoice = voicefile; //} //else { // listvoice = listvoice + "|" + voicefile; //} } } #endregion k = k + 1; } #endregion #region // ghép voice vào 1 file mp3 string[] mangvoice = new string[_DuLieu.Rows.Count]; //int indexvoice = 0; //foreach (DataRow row in _DuLieu.Rows) //{ // mangvoice[indexvoice] = row["FileVoice"].ToString(); // indexvoice = indexvoice + 1; //} //string pathvoice = txtfloderout.Text + @"\Out" + @"\" + _id.ToString() + ".mp3"; //string kq = mashup.CreateMashup(mangvoice, pathvoice); //RunFFMPEG ffghepvoice = new RunFFMPEG(); //string pathvoice= txtfloderout.Text + @"\Out" + @"\" + _id.ToString() + ".mp3"; //string ghepvoice = string.Format(@"-i ""concat:"+listvoice+@"""-acodec copy {0}", pathvoice); //ffghepvoice.RunCommand(ghepvoice, true); #endregion ChomeClose(); #region // nén và upload file lên server if (Directory.Exists(txtfloderout.Text + @"\Out\" + r["ID"].ToString())) { #region // upload file len server try { foreach (Process proc in Process.GetProcessesByName("WinRAR")) { proc.Kill(); } } catch { } string urlupload = "http://buudienhanoi.com.vn/ThangBDHN_Luu/UpLoadVoice.aspx"; WebClient myWebClient = new WebClient(); string rar_file = txtfloderout.Text + @"\Out" + @"\" + _id.ToString() + ".zip"; CompressRAR(rar_file, txtfloderout.Text + @"\Out\" + r["ID"].ToString()); Thread.Sleep(1000); byte[] responseArray = myWebClient.UploadFile(urlupload, rar_file); myWebClient.Dispose(); Thread.Sleep(1000); string m_PathVoice = "/FileVoice/" + _id.ToString() + ".zip"; WS_Service.WS_Service voice = new WS_Service.WS_Service(); voice.UpdateDaRender(Guid.Parse(_id), m_PathVoice); XoaFilemp3(txtfloderout.Text + @"\Out\" + r["ID"].ToString()); try { foreach (Process proc in Process.GetProcessesByName("WinRAR")) { proc.Kill(); } } catch { } #endregion } #endregion } }