本文整理汇总了C#中NAudio.Wave.WaveFileWriter.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# WaveFileWriter.Flush方法的具体用法?C# WaveFileWriter.Flush怎么用?C# WaveFileWriter.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NAudio.Wave.WaveFileWriter
的用法示例。
在下文中一共展示了WaveFileWriter.Flush方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FlushUpdatesHeaderEvenIfDisposeNotCalled
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
}
示例2: sourceStreamDataAvailable
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;
}
示例3: Processing
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)
{
}
}
示例4: CompileSong
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();
}
}
示例5: RecordAudioFile
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);
}
示例6: ConvertToWave
// 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;
}
示例7: ProcessPP
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));
}
}
示例8: ToAudioFile
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();
}
示例9: WriteToFile
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();
}
}
示例10: BuildTTS
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() };
}
}
}