本文整理汇总了C#中NAudio.Wave.WaveFileWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# WaveFileWriter.Write方法的具体用法?C# WaveFileWriter.Write怎么用?C# WaveFileWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NAudio.Wave.WaveFileWriter
的用法示例。
在下文中一共展示了WaveFileWriter.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ReaderShouldReadBackSameDataWrittenWithWrite
public void ReaderShouldReadBackSameDataWrittenWithWrite()
{
var ms = new MemoryStream();
var testSequence = new byte[] { 0x1, 0x2, 0xFF, 0xFE };
using (var writer = new WaveFileWriter(new IgnoreDisposeStream(ms), new WaveFormat(16000, 24, 1)))
{
writer.Write(testSequence, 0, testSequence.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);
}
}
}
示例3: 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;
}
示例4: ConvertWavTo10SecondWavs
private void ConvertWavTo10SecondWavs(FileInfo inputFile)
{
var samplesOutWav = @"..\..\..\samples\wav10seconds\";
using (var inAudio = new WaveFileReader(inputFile.FullName))
{
//Calculate required byte[] buffer.
var buffer = new byte[10*inAudio.WaveFormat.AverageBytesPerSecond];//Assume average will be constant for WAV format.
int index = 0;
do
{
var outFile = string.Format("{0}{1}.{2:0000}.wav",
samplesOutWav, inputFile.Name.Replace(inputFile.Extension, string.Empty), index);
int bytesRead = 0;
do
{
bytesRead = inAudio.Read(buffer, 0, buffer.Length - bytesRead);
} while (bytesRead > 0 && bytesRead < buffer.Length);
//Write new file
using (var waveWriter = new WaveFileWriter(outFile, inAudio.WaveFormat))
{
waveWriter.Write(buffer, 0, buffer.Length);
}
index++;
} while (inAudio.Position < inAudio.Length);
}
}
示例5: 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)
{
}
}
示例6: CanDownsampleAnMp3File
public void CanDownsampleAnMp3File()
{
string testFile = @"D:\Audio\Music\Coldplay\Mylo Xyloto\03 - Paradise.mp3";
if (!File.Exists(testFile)) Assert.Ignore(testFile);
string outFile = @"d:\test22.wav";
using (var reader = new AudioFileReader(testFile))
{
// downsample to 22kHz
var resampler = new WdlResamplingSampleProvider(reader, 22050);
var wp = new SampleToWaveProvider(resampler);
using (var writer = new WaveFileWriter(outFile, wp.WaveFormat))
{
byte[] b = new byte[wp.WaveFormat.AverageBytesPerSecond];
while (true)
{
int read = wp.Read(b, 0, b.Length);
if (read > 0)
writer.Write(b, 0, read);
else
break;
}
}
//WaveFileWriter.CreateWaveFile(outFile, );
}
}
示例7: Extract
private static void Extract(Stream output, WaveStream waveStream, byte[] buffer)
{
if (waveStream == null)
return;
using (WaveFileWriter writer = new WaveFileWriter(output, waveStream.WaveFormat))
{
int count;
while ((count = waveStream.Read(buffer, 0, buffer.Length)) != 0)
writer.Write(buffer, 0, count);
}
}
示例8: 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();
}
}
示例9: CreateWaveFile
/// <summary>
/// Creates a Wave file by reading all the data from a WaveProvider
/// BEWARE: the WaveProvider MUST return 0 from its Read method when it is finished,
/// or the Wave File will grow indefinitely.
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="sourceProvider">The source WaveProvider</param>
public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
{
using (WaveFileWriter writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
{
byte[] buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
writer.Write(buffer, 0, bytesRead);
}
}
}
示例10: CreateWaveFile
public void CreateWaveFile(string outputFile)
{
Console.WriteLine("Saving wav file: " + outputFile);
using (WaveFileWriter writer = new WaveFileWriter(outputFile, this.VstStream.WaveFormat))
{
byte[] buf = new byte[this.blocksize];
for (; ;)
{
int cnt = this.VstStream.Read(buf, 0, buf.Length);
if (cnt == 0) break;
writer.Write(buf, 0, cnt);
}
}
}
示例11: ConvertAiffToWav
private static void ConvertAiffToWav(string aiffFile, string wavFile)
{
using (var reader = new AiffFileReader(aiffFile))
{
using (var writer = new WaveFileWriter(wavFile, reader.WaveFormat))
{
byte[] buffer = new byte[4096];
int bytesRead = 0;
do
{
bytesRead = reader.Read(buffer, 0, buffer.Length);
writer.Write(buffer, 0, bytesRead);
} while (bytesRead > 0);
}
}
}
示例12: TrimWavFile
private static void TrimWavFile(WaveFileReader paramWavReader, WaveFileWriter paramWavWriter, int paramStartPosition, int paramEndPosition)
{
paramWavReader.Position = paramStartPosition;
Byte[] byteBuffer = new Byte[1024];
while (paramWavWriter.Length < paramEndPosition)
{
int bytesRequired = (int)(paramEndPosition - paramWavReader.Position);
if (bytesRequired > 0)
{
int bytesToRead = Math.Min(bytesRequired, byteBuffer.Length);
int bytesRead = paramWavReader.Read(byteBuffer, 0, bytesToRead);
if (bytesRead > 0)
{
paramWavWriter.Write(byteBuffer, 0, bytesRead);
}
}
}
}
示例13: TrimWavFile
private static void TrimWavFile(WaveFileReader reader, WaveFileWriter writer, int startPos, int endPos)
{
reader.Position = startPos;
byte[] buffer = new byte[1024];
while (reader.Position < endPos)
{
int bytesRequired = (int)(endPos - reader.Position);
if (bytesRequired > 0)
{
int bytesToRead = Math.Min(bytesRequired, buffer.Length);
int bytesRead = reader.Read(buffer, 0, bytesToRead);
if (bytesRead > 0)
{
writer.Write(buffer, 0, bytesRead);
}
}
}
}
示例14: CreateWaveFile
/// <summary>
/// Creates a Wave file by reading all the data from a WaveProvider
/// BEWARE: the WaveProvider MUST return 0 from its Read method when it is finished,
/// or the Wave File will grow indefinitely.
/// </summary>
/// <param name="filename">The filename to use</param>
/// <param name="sourceProvider">The source WaveProvider</param>
public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
{
using (var writer = new WaveFileWriter(filename, sourceProvider.WaveFormat))
{
var buffer = new byte[sourceProvider.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = sourceProvider.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
// end of source provider
break;
}
// Write will throw exception if WAV file becomes too large
writer.Write(buffer, 0, bytesRead);
}
}
}
示例15: CutWavFile
private void CutWavFile(WaveFileReader reader, WaveFileWriter writer, int startPos, int endPos, Action<long> progressCallback)
{
reader.Position = startPos;
byte[] buffer = new byte[1024];
while (reader.Position < endPos)
{
var bytesRequired = (int)(endPos - reader.Position);
if (bytesRequired > 0)
{
int bytesToRead = Math.Min(bytesRequired, buffer.Length);
int bytesRead = reader.Read(buffer, 0, bytesToRead);
if (bytesRead > 0)
{
writer.Write(buffer, 0, bytesRead);
}
progressCallback(bytesRead);
}
}
}