private void Processing() { try { using (var waveWriterYour = new WaveFileWriter(@"F:\Desktop\\Recordshit\\" + Environment.UserName + " - " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".wav", new WaveFormat(48000, 16, 2))) while (true) { byte[] bufBytes; if (BufferCollection.TryTake(out bufBytes, Timeout.Infinite)) { if (bufBytes.Length == 0 || !_socketClient.Connected) break; _socketClient.Send(bufBytes); waveWriterYour.Write(bufBytes, 0, bufBytes.Length); waveWriterYour.Flush(); } else { break; } } } catch (Exception e) { } }
private void sourceStreamDataAvailable(object sender, WaveInEventArgs e) { string path = outputPath + "wavsam" + nFiles + ".wav"; writer = new WaveFileWriter(path, waveFormat); writer.Write(e.Buffer, 0, e.Buffer.Length); writer.Flush(); writer.Close(); nFiles++; Process process = new Process(); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = "praatcon.exe"; String male; if (isMale) male = "yes"; else male = "no"; process.StartInfo.Arguments = "extract_measures.praat " + path + " " + male; // process.StartInfo.RedirectStandardOutput = true; process.Start(); process.WaitForExit(); ResultEventArgs args = new ResultEventArgs(); // args.text = output; OnResults(args); // args.nWords = err.Length; }
public void FlushUpdatesHeaderEvenIfDisposeNotCalled() { var ms = new MemoryStream(); var testSequence = new byte[] { 0x1, 0x2, 0xFF, 0xFE }; var testSequence2 = new byte[] { 0x3, 0x4, 0x5 }; var writer = new WaveFileWriter(new IgnoreDisposeStream(ms), new WaveFormat(16000, 24, 1)); writer.Write(testSequence, 0, testSequence.Length); writer.Flush(); // BUT NOT DISPOSED // another write that was not flushed writer.Write(testSequence2, 0, testSequence2.Length); // check the Reader can read it ms.Position = 0; using (var reader = new WaveFileReader(ms)) { Assert.AreEqual(16000, reader.WaveFormat.SampleRate, "Sample Rate"); Assert.AreEqual(24, reader.WaveFormat.BitsPerSample, "Bits Per Sample"); Assert.AreEqual(1, reader.WaveFormat.Channels, "Channels"); Assert.AreEqual(testSequence.Length, reader.Length, "File Length"); var buffer = new byte[600]; // 24 bit audio, block align is 3 int read = reader.Read(buffer, 0, buffer.Length); Assert.AreEqual(testSequence.Length, read, "Data Length"); for (int n = 0; n < read; n++) { Assert.AreEqual(testSequence[n], buffer[n], "Byte " + n); } } writer.Dispose(); // to stop the finalizer from moaning }
//Event args to check if Data is available private void wavSource_DataAvail(object sender, NAudio.Wave.WaveInEventArgs e) { if (wavFile != null) { wavFile.Write(e.Buffer, 0, e.BytesRecorded); wavFile.Flush(); } }
public void waveSource_DataAvailable(object sender, WaveInEventArgs e) { if (WaveFile != null) { WaveFile.Write(e.Buffer, 0, e.BytesRecorded); WaveFile.Flush(); } }
private NAudio.Wave.WaveFileWriter waveWriter = null; // zapisywanie pliku // WaveInEventArgs - jesli zmienia się pobierany dzwiek to private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e) { if (waveWriter == null) { return; } waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded); //buforujemy dane waveWriter.Flush(); // czyszczenie buforu dla tego strumienia }
private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e) { if (waveWriter == null) { return; } waveWriter.Write(e.Buffer, 0, e.BytesRecorded); waveWriter.Flush(); }
private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e) { if (waveWriter == null) { return; } waveWriter.Write(e.Buffer, 0, e.BytesRecorded); sampleLocation += e.BytesRecorded / 4; labelCurrentTime.Text = ((double)sampleLocation / (double)sampleRate).ToString(); waveWriter.Flush(); }
static void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e) { if (waveWriter == null) { return; } waveWriter.Write(e.Buffer, 0, e.BytesRecorded); sampleLocation += e.BytesRecorded / 4; Debug.Print(((double)sampleLocation / (double)sampleRate).ToString()); waveWriter.Flush(); }
private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e) { if (waveWriter == null) { return; } waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded); waveWriter.Flush(); int timer = (int)(waveWriter.Length / waveWriter.WaveFormat.AverageBytesPerSecond); int hora = 0; int minu = 0; int seg = 0; string tSeg = null, tMin = null, tHora = null; if (timer >= 60) { minu = (int)(timer / 60); if (minu >= 60) { hora = (int)(minu / 60); minu = minu % 60; } seg = timer % 60; tHora = hora < 10 ? "0" + hora.ToString() : tHora = hora.ToString(); tMin = minu < 10 ? "0" + minu.ToString() : tMin = minu.ToString(); tSeg = seg < 10 ? "0" + seg.ToString() : tSeg = seg.ToString(); timerHora.Text = tHora; timerMinuto.Text = tMin; timerSec.Text = tSeg; } else { if (timer < 10) { tSeg = "0" + timer.ToString(); } else { tSeg = timer.ToString(); } timerSec.Text = tSeg; } var device = (MMDevice)micList.SelectedItem; WaveAudioLevel.Value = (int)(Math.Round(device.AudioMeterInformation.MasterPeakValue * 100)); }
public static void CompileSong(string path) { StreamReader inputStream = new StreamReader(@"Content/" + path + ".mp3"); StreamWriter outputStream = new StreamWriter(@"Content/" + path + ".wav"); using (WaveStream waveStream = WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(inputStream.BaseStream))) using (WaveFileWriter waveFileWriter = new WaveFileWriter(outputStream.BaseStream, waveStream.WaveFormat)) { byte[] bytes = new byte[waveStream.Length]; waveStream.Read(bytes, 0, (int)waveStream.Length); waveFileWriter.Write(bytes, 0, bytes.Length); waveFileWriter.Flush(); } }
public virtual void RecordAudioFile() { string currentDirectory = AppDomain.CurrentDomain.BaseDirectory; string wavFile = Path.Combine (currentDirectory, "recording.wav"); long writtenSamples = 0; WaveFileWriter writer = new WaveFileWriter (wavFile, _jackIn.WaveFormat); _jackIn.DataAvailable += (sender, args) => { writer.Write (args.Buffer, 0, args.BytesRecorded); }; _jackIn.RecordingStopped += (sender, e) => { writer.Flush (); writer.Dispose (); long fileSize = new FileInfo (wavFile).Length; Assert.AreNotEqual (0, fileSize); }; _jackIn.StartRecording (); Thread.Sleep (100); _jackIn.StopRecording (); writtenSamples = writer.Length; Assert.AreNotEqual (0, writtenSamples); }
// First need to convert to wave format. private byte[] ConvertToWave(IList<Sample> samples, WaveFormat waveFormat) { byte[] result = null; using (MemoryStream memoryStream = new MemoryStream()) { using (WaveFileWriter writer = new WaveFileWriter(memoryStream, waveFormat)) { foreach (Sample sample in samples) { writer.Write(sample.Value, 0, sample.Value.Length); } // Writer won't finish on its own until it's disposed. writer.Flush(); // Need to do this here because disposing the writer will close the memory stream. result = memoryStream.ToArray(); } } return result; }
//Event arguments to write data private void wavSource_DataAvailable(object sender, WaveInEventArgs e) { wavFile.Write(e.Buffer, 0, e.BytesRecorded); totalBytes.AddRange(e.Buffer); wavFile.Flush(); byte[] shots = new byte[4]; for (int i = 0; i < e.BytesRecorded - 1; i += 100) { shots[0] = e.Buffer[i]; shots[1] = e.Buffer[i + 1]; shots[2] = e.Buffer[i + 2]; shots[3] = e.Buffer[i + 3]; if (counter < numToDisp) { dispShots.Enqueue(BitConverter.ToInt32(shots, 0)); counter++; } else { dispShots.Dequeue(); dispShots.Enqueue(BitConverter.ToInt32(shots, 0)); } } this.waveCanvas.Children.Clear(); polyLine.Points.Clear(); Int32[] shots2 = dispShots.ToArray(); for (Int32 i = 0; i < shots2.Length; i++) { polyLine.Points.Add(Normalize(i, shots2[i])); } this.waveCanvas.Children.Add(polyLine); }
// Functions which writes chunks of samples to the wav file private void OnDataAvailable(object sender, NAudio.Wave.WaveInEventArgs e) { waveWriter.Write(e.Buffer, 0, e.BytesRecorded); waveWriter.Flush(); }
protected override BakedTTS BuildTTS(IVoice voice, string text, double rate, int pitch) { var tts = RequestTTS((L2FVoice)voice, text); if (tts == null) return null; //Create visemes List<VisemeSpan> visemes = new List<VisemeSpan>(); //Convert phones to visemes and adjust time to rate var mapper = LanguageResources.PT_PhonesToVisemes; Viseme lastViseme = Viseme.Silence; double totalVisemeTime = 0; foreach (var r in tts) { var phones = ((JsonArray)r["phones"]).Select(t => ((JsonString)t).String); var time = ((JsonArray) r["times"]).Select(t => Convert.ToDouble(((JsonNumber) t).Value)); var toProcess = phones.Zip(time, (s, d) => new { ph = s, entryTime = d }).ToArray(); totalVisemeTime += toProcess[0].entryTime;///rate; lastViseme = Viseme.Silence; for (int i = 1; i < toProcess.Length-1; i++) { var p = toProcess[i]; var nextTime = toProcess[i+1].entryTime; Viseme currentViseme; if (!mapper.TryGetValue(p.ph, out currentViseme)) currentViseme = Viseme.Silence; if (lastViseme != currentViseme) { visemes.Add(new VisemeSpan() { duration = totalVisemeTime/rate, viseme = lastViseme }); lastViseme = currentViseme; totalVisemeTime = 0; } var duration = nextTime - p.entryTime; totalVisemeTime += duration; } } if(totalVisemeTime>0) visemes.Add(new VisemeSpan() { duration = totalVisemeTime/rate, viseme = lastViseme }); if (visemes.Count == 0) return null; //Create audio var audioUrls = tts.Select(r => ((JsonString)r["url"]).String).ToArray(); var v = BuildAudioStream(audioUrls, rate, pitch); const int MAX_SAMPLES = 5120; var bufferSize = MAX_SAMPLES * v.WaveFormat.Channels; var buffer = new float[bufferSize]; using (var m = new MemoryStream()) { using (var w = new WaveFileWriter(m, v.WaveFormat)) { int readed; while ((readed = v.Read(buffer, 0, bufferSize)) > 0) { w.WriteSamples(buffer, 0, readed); } w.Flush(); return new BakedTTS() { visemes = visemes.ToArray(), waveStreamData = m.ToArray() }; } } }
private void WriteToFile() { if (wf.Channels == 1) { WaveFormat nwf = new WaveFormat(22050, 16, 1); File.Delete("a.wav"); WaveFileWriter writer = new WaveFileWriter("a.wav", wf); writer.Write(buffer, 0, buffer.Length); writer.Flush(); } else { backToByte(left, right); WaveFormat nwf = new WaveFormat(22050, 8, 1); File.Delete("a.wav"); WaveFileWriter writer = new WaveFileWriter("a.wav", wf); writer.Write(bufout, 0, bufout.Length); writer.Flush(); } }
public static void ToAudioFile(this ISampleProvider provider, string audioFileName) { IWaveProvider wave = provider.ToWaveProvider(); WaveFileWriter writer = new WaveFileWriter(audioFileName, provider.WaveFormat); int readed; byte[] buffer = new byte[65536]; while ((readed = wave.Read(buffer, 0, buffer.Length)) != 0) { writer.Write(buffer, 0, readed); } writer.Flush(); }
public void ProcessPP(ppParser pp) { for (int i = 0; i < pp.Subfiles.Count; i++) { IWriteFile iw = pp.Subfiles[i]; if (!iw.Name.EndsWith(".wav")) continue; Stream str = Tools.GetReadStream(iw); if (!str.CanSeek || str.Length == 0) { str.Close(); continue; } using (str) using (WaveFileReader wv = new WaveFileReader(str)) { if (wv.WaveFormat.Channels > 1 || wv.WaveFormat.SampleRate > SampleRate) // || wv.WaveFormat.Encoding != WaveFormatEncoding.Adpcm { WaveFormat f = new WaveFormat(SampleRate, 16, 1); //new AdpcmWaveFormat(wv.WaveFormat.SampleRate, 1); using (MediaFoundationResampler resampledAudio = new MediaFoundationResampler(wv, f)) { resampledAudio.ResamplerQuality = 60; MemoryStream o = new MemoryStream(); using (WaveFileWriter wr = new WaveFileWriter(o, f)) { int count = 0; byte[] buffer = new byte[2048]; while ((count = resampledAudio.Read(buffer, 0, 2048)) > 0) { wr.Write(buffer, 0, count); } wr.Flush(); pp.Subfiles[i] = new MemSubfile(ToByteArray(o), iw.Name); } } } } if (ProgressUpdated != null) ProgressUpdated((int)Math.Floor((double)(100 * i) / pp.Subfiles.Count)); } }