public ActionResult ThemMoi(audio audio, HttpPostedFileBase fileUpload) { //Đưa dữ liệu vào dropdownlist ViewBag.idChuDe = new SelectList(db.chudes.ToList().OrderBy(n => n.chuDe), "idChuDe", "chuDe"); //kiểm tra đường dẫn url if (fileUpload == null) { ViewBag.ThongBao = "Chọn File"; return(View()); } //Thêm vào cơ sở dữ liệu if (ModelState.IsValid) { //Lưu tên file var fileName = Path.GetFileName(fileUpload.FileName); //Lưu đường dẫn của file var path = Path.Combine(Server.MapPath("~/fileAudio"), fileName); //Kiểm tra file đã tồn tại chưa if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "File đã tồn tại"; } else { fileUpload.SaveAs(path); } audio.url = fileUpload.FileName; db.audios.Add(audio); db.SaveChanges(); } return(View()); }
private void Button_OnClick(object?sender, RoutedEventArgs e) { var textBox = this.Find <TextBox>("text"); if (!string.IsNullOrEmpty(textBox.Text)) { var req = WebRequest.Create("http://127.0.0.1:5000"); req.Method = "POST"; using (var rStream = req.GetRequestStream()) { var mes = new audio { Content = ByteString.Empty, Text = textBox.Text, Date = DateTime.Now.ToString() }; mes.WriteTo(rStream); } var resp = req.GetResponse(); var stream = resp.GetResponseStream(); var audi = audio.Parser.ParseFrom(stream); stream.Close(); byte[] content = audi.Content.ToByteArray(); File.WriteAllBytes("audio.wav", content); var command = "afplay " + Path.GetFullPath("audio.wav"); ExecuteCommand(command); } }
void WhichAudio(audio play) { switch (play) { case audio.Hood: Speaker.clip = StartSound; Speaker.Play(); NextPlaying = audio.HoodSecond; StartCoroutine(WaitTillDone()); break; case audio.HoodSecond: Speaker.clip = EndSound; Speaker.PlayDelayed(3); break; case audio.Pause: paused = true; Speaker.Pause(); break; case audio.UnPause: paused = false; Speaker.UnPause(); break; case audio.CloseHood: Speaker.clip = CloseHood; Speaker.PlayDelayed(1); stillPlay = false; break; } }
internal void sleep() { if (currState != audio.sleep) { sleepState = currState; currState = audio.sleep; } }
public string Get_Json(string content, string lang) { audio aud = new audio(content); conf.languageCode = lang; Request rc = new Request(conf, aud); return(JsonUtility.ToJson(rc)); }
public void Play(string name) { audio s = Array.Find(sounds, sound => sound.name == name); if (s == null) { return; } s.AuSource.Play(); }
public ActionResult Checks(audio a) { var audio = db.audios.SingleOrDefault(n => n.idAudio == a.idAudio); audio.checks = 1; audio.diem = a.diem; db.Entry(audio).Property("checks").IsModified = true; db.Entry(audio).Property("diem").IsModified = true; db.SaveChanges(); return(Redirect(Request.UrlReferrer.ToString())); }
public void playManager(string tag) { if (paused) { WhichAudio(audio.UnPause); } else { audio stringToEnum = (audio)System.Enum.Parse(typeof(audio), tag); WhichAudio(stringToEnum); } }
public ActionResult XacNhanXoa(int idAudio) { audio audio = db.audios.SingleOrDefault(n => n.idAudio == idAudio); if (audio == null) { Response.StatusCode = 404; return(null); } db.audios.Remove(audio); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Xoa(int idAudio) { //Lấy ra đối tượng audio theo mã audio audio = db.audios.SingleOrDefault(n => n.idAudio == idAudio); if (audio == null) { Response.StatusCode = 404; return(null); } return(View(audio)); }
public ActionResult ChinhSua(int idAudio) { //Lấy ra đối tượng audio theo mã audio audio = db.audios.SingleOrDefault(n => n.idAudio == idAudio); if (audio == null) { Response.StatusCode = 404; return(null); } //Đưa dữ liệu vào dropdownlist ViewBag.idChuDe = new SelectList(db.chudes.ToList().OrderBy(n => n.idChuDe), "idChuDe", "chuDe", audio.idChuDe); return(View(audio)); }
/// <summary> /// Updates the audio record in the database corresponding to the given audioRecordId so its audio_lob is set to an /// empty byte array. Purged is set to true. The date_last_modified and last_modified_by properties are also set. /// </summary> /// <param name="audioRecordId"></param> /// <param name="db"></param> public static void PurgeAudioRecord(int audioRecordId, trackdocEntities db) { var exsitingAudioToPurge = new audio(); exsitingAudioToPurge.id = audioRecordId; exsitingAudioToPurge.audio_lob = new byte[0]; exsitingAudioToPurge.purged = true; exsitingAudioToPurge.date_last_modified = DateTime.Now; exsitingAudioToPurge.last_modified_by = 0; db.audios.Attach(exsitingAudioToPurge); db.Entry(exsitingAudioToPurge).Property(d => d.purged).IsModified = true; db.Entry(exsitingAudioToPurge).Property(d => d.audio_lob).IsModified = true; db.Entry(exsitingAudioToPurge).Property(d => d.date_last_modified).IsModified = true; db.Entry(exsitingAudioToPurge).Property(d => d.last_modified_by).IsModified = true; db.Configuration.ValidateOnSaveEnabled = false;// Needed because some of the properties we're ignoring are required. db.SaveChanges(); }
void Update() { if (audio_list.Count == 0) { return; } for (int i = audio_list.Count - 1; i >= 0; i--) { audio audio = audio_list[i]; if (audio.wait_time > 0) { audio.wait_time--; } else { GameObject obj = Instantiate(audio_map[audio.audio_code]) as GameObject; audio_list.Remove(audio); } } }
public ActionResult ChinhSua(audio audio, FormCollection f) { //Sach sach1 = db.Saches.SingleOrDefault(n => n.MaSach == sach.MaSach); //sach1.MoTa = sach.MoTa; //sach1.MoTa = f.Get("abc").ToString(); //sach.MoTa = f["abc"].ToString(); //db.SaveChanges(); //Thêm vào cơ sở dữ liệu if (ModelState.IsValid) { //Thực hiện cập nhận trong model db.Entry(audio).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //Đưa dữ liệu vào dropdownlist ViewBag.idChuDe = new SelectList(db.chudes.ToList().OrderBy(n => n.idChuDe), "idChuDe", "chuDe", audio.idChuDe); return(RedirectToAction("Index")); }
internal AudioStateMachine() { currState = audio.sleep; //fill array with functions getNextState = new machine[] { Sleep, Music, SFX, Exit }; }
//downloads audio and audio thumbs and saves it to local temp in particular album's directory. This feature will be used in the future to allow the users to listen to audios as well inside the software private static bool downloadaudio(audio audiotodownload, Int32 playlistid) { try { string pathtotemp = System.Windows.Forms.Application.StartupPath + "\\temp"; if (!Directory.Exists(pathtotemp)) Directory.CreateDirectory(pathtotemp); string pathtoplaylist = pathtotemp + "\\playlist_" + playlistid; if (!Directory.Exists(pathtoplaylist)) Directory.CreateDirectory(pathtoplaylist); if (!Directory.Exists(pathtoplaylist + "\\audios")) Directory.CreateDirectory(pathtoplaylist + "\\audios"); //if (!Directory.Exists(pathtoplaylist + "\\thumbs")) Directory.CreateDirectory(pathtoplaylist + "\\thumbs"); string audiofilename = pathtoplaylist + "\\audios\\" + audiotodownload.name; //string audiothumbfilename = pathtoplaylist + "\\thumbs\\" + audiotodownload.thumb; //skipped downloading of the audio that would take a whole lot of time //if (!File.Exists(audiofilename)) //{ // FileStream fs = new FileStream(audiofilename, FileMode.Create); // string remotepicturefilename = "user_" + userid + "/playlist_" + playlistid + "/audios/" + audiotodownload.name; // FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpurl + remotepicturefilename); // request.Method = WebRequestMethods.Ftp.DownloadFile; // request.Credentials = new NetworkCredential(ftpusername, ftppassword); // FtpWebResponse response = (FtpWebResponse)request.GetResponse(); // Stream responseStream = response.GetResponseStream(); // byte[] buffer = new byte[1024]; // int bytesread = 0; // while ((bytesread = responseStream.Read(buffer, 0, buffer.Length)) > 0) // fs.Write(buffer, 0, bytesread); // fs.Close(); // responseStream.Close(); // response.Close(); //} //if (!File.Exists(audiothumbfilename)) //{ // FileStream fs = new FileStream(audiothumbfilename, FileMode.Create); // string remotealbumthumb = "user_" + userid + "/playlist_" + playlistid + "/thumbs/" + audiotodownload.thumb; // FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpurl + remotealbumthumb); // request.Method = WebRequestMethods.Ftp.DownloadFile; // request.Credentials = new NetworkCredential(ftpusername, ftppassword); // FtpWebResponse response = (FtpWebResponse)request.GetResponse(); // Stream responseStream = response.GetResponseStream(); // byte[] buffer = new byte[1024]; // int bytesread = 0; // while ((bytesread = responseStream.Read(buffer, 0, buffer.Length)) > 0) // fs.Write(buffer, 0, bytesread); // fs.Close(); // responseStream.Close(); // response.Close(); //} } catch { return false; } return true; }
internal void wake() { currState = sleepState; }
internal void goTo(audio state) { currState = state; }
public void TestShow(audio.PitchResult result) { lock (_result) { _result = result; } panel1.Invalidate(); }
public Request(config c, audio aud) { config = c; audio = aud; }
void Awake() { S = this; }
private void drawWave(Surface s, audio.PitchResult pitch, audio.ToneResult tone, SdlDotNet.Graphics.Font font, Rectangle rect) { if (pitch != null) { double dx = rect.Width / (double)pitch.Length; int width = rect.Width; int height = rect.Height; #region 波形用点列作成 double maxPower = double.MinValue; double maxCorrelation = double.MinValue; double minCorrelation = double.MaxValue; for (int i = 0; i < pitch.Length; i++) { if (maxPower < pitch.Power[i]) maxPower = pitch.Power[i]; if (maxCorrelation < pitch.Correlation[i]) maxCorrelation = pitch.Correlation[i]; if (minCorrelation > pitch.Correlation[i]) minCorrelation = pitch.Correlation[i]; } if (maxCorrelation > -minCorrelation) minCorrelation = -maxCorrelation; else maxCorrelation = -minCorrelation; List<Point> signal = new List<Point>(); List<Point> nsdf = new List<Point>(); List<Point> power = new List<Point>(); double x = rect.X; for (int i = 0; i < pitch.Length; i++) { signal.Add(new Point((int)x, (int)(rect.Bottom - rect.Height * (pitch.Signal[i] + 1) / 2.0))); // 入力波 nsdf.Add(new Point((int)x, (int)(rect.Bottom - rect.Height * (pitch.NSDF[i] + 1) / 2.0))); // NSDF power.Add(new Point((int)x, (int)(rect.Bottom - rect.Height * (pitch.Power[i] / (maxPower == 0 ? 1.0 : maxPower))))); // Power x += dx; } #endregion // 波形描画 drawLines(s, nsdf, _nsdfColor); drawLines(s, power, _powerColor); drawLines(s, signal, _signalColor); } // 枠 Box box = new Box(rect.Location, rect.Size); s.Draw(box, Constants.Color_Foreground, true, false); s.Draw(new Line( new Point(rect.X, rect.Top + (int)(rect.Height / 2.0)), new Point(rect.Right, rect.Top + (int)(rect.Height / 2.0))), Constants.Color_Foreground); }
void run() { try { HttpResponseMessage response = client.GetAsync(url).Result; string startTimestamp = DateTime.Now.ToString().Replace(":", "-"); if (response.StatusCode == System.Net.HttpStatusCode.OK) { string data = ASCIIEncoding.ASCII.GetString(response.Content.ReadAsByteArrayAsync().Result); string fileName = exeDirectory + startTimestamp + "-master.json"; File.WriteAllText(fileName, data); container c = JsonConvert.DeserializeObject <container>(data); if (c != null) { int segmentsCount = 0; run_processStarted(); video videoSegments = null; audio audioSegments = null; //calculate segments count using audio or video stream if (c.audios != null && c.audios.Length > 0) { audioSegments = c.audios[c.audios.Length - 1]; segmentsCount = audioSegments.segments.Length; } if (c.videos != null && c.videos.Length > 0) { videoSegments = c.videos[0]; //берём лудшую качеству foreach (video v in c.videos) { if (v.width > videoSegments.width) { videoSegments = v; segmentsCount = videoSegments.segments.Length; } } } if (segmentsCount > 0) { run_updateProgress(0, segmentsCount); int sepIndex = url.IndexOf("/sep/"); string baseUrl = url.Substring(0, sepIndex + 5); string videoUrl = baseUrl + video.path + videoSegments.base_url; string audioUrl = baseUrl + audioSegments.base_url.Replace("../", ""); Directory.CreateDirectory(exeDirectory + startTimestamp); string directory = exeDirectory + startTimestamp; List <string> audioFilesList = new List <string>(); List <string> videoFilesList = new List <string>(); // zero segment stored in json file if (audioSegments != null) { string audioFileName = directory + "\\a[0000].m4s"; File.WriteAllBytes(audioFileName, audioSegments.segment0); audioFilesList.Add(audioFileName); } if (videoSegments != null) { string videoFileName = directory + "\\v[0000].m4s"; File.WriteAllBytes(videoFileName, videoSegments.segment0); videoFilesList.Add(videoFileName); } HttpClient audioClient = new HttpClient(); HttpClient videoClient = new HttpClient(); for (int i = 0; i < segmentsCount; i++) { if (shouldStop) { return; } //for index 0 we have name (and real part) 1.m4s string videoSegmentUrl = videoUrl + videoSegments.segments[i].url; string audioSegmentUrl = audioUrl + videoSegments.segments[i].url; string videoFileName = directory + String.Format("\\v[{0:d4}].m4s", i + 1); string audioFileName = directory + String.Format("\\a[{0:d4}].m4s", i + 1); var vTask = videoClient.GetAsync(videoSegmentUrl); var aTask = audioClient.GetAsync(audioSegmentUrl); byte[] vData = vTask.Result.Content.ReadAsByteArrayAsync().Result; byte[] aData = aTask.Result.Content.ReadAsByteArrayAsync().Result; File.WriteAllBytes(videoFileName, vData); File.WriteAllBytes(audioFileName, aData); audioFilesList.Add(audioFileName); videoFilesList.Add(videoFileName); if (shouldStop) { return; } run_updateProgress(i, segmentsCount); } string concatAudioFileName = directory + "\\audio.m4s"; string concatVideoFileName = directory + "\\video.m4s"; //concatenate files using (FileStream fs = File.Create(concatAudioFileName)) { for (int i = 0; i < audioFilesList.Count; i++) { byte[] tmpData = File.ReadAllBytes(audioFilesList[i]); fs.Write(tmpData, 0, tmpData.Length); run_updateProgress(i, segmentsCount); } } using (FileStream fs = File.Create(concatVideoFileName)) { for (int i = 0; i < videoFilesList.Count; i++) { byte[] tmpData = File.ReadAllBytes(videoFilesList[i]); fs.Write(tmpData, 0, tmpData.Length); run_updateProgress(i, segmentsCount); } } //concatenate video+audio ProcessStartInfo cmd = new ProcessStartInfo(exeDirectory + "ffmpeg.exe", String.Format("-i \"{0}\\video.m4s\" -i \"{0}\\audio.m4s\" -c copy \"{0}\\output.mp4\"", directory)); cmd.WorkingDirectory = directory; Process pConcatenate = Process.Start(cmd); //delete temprory files if (checkBoxDeleteTemp.Checked) { for (int i = 0; i < videoFilesList.Count; i++) { File.Delete(videoFilesList[i]); File.Delete(audioFilesList[i]); run_updateProgress(i, segmentsCount); } while (!pConcatenate.HasExited) { if (shouldStop) { return; } Thread.Sleep(100); } File.Delete(concatAudioFileName); File.Delete(concatVideoFileName); } if (checkBoxMove.Checked) { string newDirectory = textBoxBaseFolder.Text + "\\" + textBoxNewFolder.Text; string src = Path.Combine(directory, "output.mp4"); string dst = Path.Combine(newDirectory, "output.mp4"); Directory.CreateDirectory(newDirectory); File.Move(src, dst); directory = newDirectory; } //open output directory ProcessStartInfo openFolder = new ProcessStartInfo { FileName = "explorer.exe", Arguments = directory }; //MessageBox.Show(openFolder.Arguments); Process.Start(openFolder); if (checkBoxClose.Checked) { run_close(); } } } } else { MessageBox.Show(response.ToString()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } if (!shouldStop) { run_resetForm(); } }
internal audio update() { return(currState = getNextState[((int)currState)]()); }