当前位置: 首页>>代码示例>>C#>>正文


C# WaveFileWriter.Write方法代码示例

本文整理汇总了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
 }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:31,代码来源:WaveFileWriterTests.cs

示例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);
         }
     }
 }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:25,代码来源:WaveFileWriterTests.cs

示例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;
        }
开发者ID:emreza,项目名称:speech_agent,代码行数:27,代码来源:Recorder.cs

示例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);
     }
 }
开发者ID:tmpreston,项目名称:BingVoiceTranscription,代码行数:26,代码来源:NAudioTasks.cs

示例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)
     {
     }
 }
开发者ID:Zerowalker,项目名称:VoiceChatWPF,代码行数:26,代码来源:BlockingCollectionHandler.cs

示例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, );
     }
 }
开发者ID:LibertyLocked,项目名称:NAudio,代码行数:25,代码来源:WdlResamplingSampleProviderTests.cs

示例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);
            }
        }
开发者ID:truongan012,项目名称:Pulse,代码行数:12,代码来源:ScdToWaveArchiveEntryExtractor.cs

示例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();
            }
        }
开发者ID:sinmaplewing,项目名称:Hare-TortoiseGame,代码行数:14,代码来源:LoadSong.cs

示例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);
         }
     }
 }
开发者ID:jayfar,项目名称:NAudio_1.5_Updates,代码行数:21,代码来源:WaveFileWriter.cs

示例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);
         }
     }
 }
开发者ID:remy22,项目名称:AudioVSTToolbox,代码行数:14,代码来源:VstPlaybackNAudio.cs

示例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);
         }
     }
 }
开发者ID:EraYaN,项目名称:Moonstone,代码行数:16,代码来源:AiffReaderTests.cs

示例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);
             }
         }
     }
 }
开发者ID:EspyingStar,项目名称:AudioQ,代码行数:18,代码来源:FileEditor.cs

示例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);
             }
         }
     }
 }
开发者ID:shawnweisfeld,项目名称:ReadingResourceRecorder,代码行数:18,代码来源:WavFileUtils.cs

示例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);
         }
     }
 }
开发者ID:ActivePHOENiX,项目名称:NAudio,代码行数:25,代码来源:WaveFileWriter.cs

示例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);
                }
            }
        }
开发者ID:olathunberg,项目名称:RecordToMP3,代码行数:20,代码来源:WaveFileCutter.cs


注:本文中的NAudio.Wave.WaveFileWriter.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。