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


C# WaveFileWriter.Close方法代码示例

本文整理汇总了C#中NAudio.Wave.WaveFileWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# WaveFileWriter.Close方法的具体用法?C# WaveFileWriter.Close怎么用?C# WaveFileWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NAudio.Wave.WaveFileWriter的用法示例。


在下文中一共展示了WaveFileWriter.Close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: Main

        static void Main(string[] args)
        {
            // for recording
            waveFileWriter = new WaveFileWriter(@"C:\rec\out.wav", new WaveFormat(44100, 2));

            var sound = new MySound();
            sound.SetWaveFormat(44100, 2);
            sound.init();
            waveOut = new WaveOut();
            waveOut.Init(sound);
            waveOut.Play();

            ConsoleKeyInfo keyInfo;
            bool loop = true;
            while (loop)
            {
                keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Q)
                {
                    waveOut.Stop();
                    waveOut.Dispose();
                    waveFileWriter.Close();
                    waveFileWriter.Dispose();
                    loop = false;
                }
            }
        }
开发者ID:ryo-okabayashi,项目名称:sound,代码行数:27,代码来源:Program.cs

示例3: ProcessAudioWave

        public static void ProcessAudioWave(string fileIn, string fileOut, float newTempo = 1, float newPitch = 1, float newRate = 1)
        {
            WaveFileReader reader = new WaveFileReader(fileIn);

            int numChannels = reader.WaveFormat.Channels;

            if (numChannels > 2)
                throw new Exception("SoundTouch supports only mono or stereo.");

            int sampleRate = reader.WaveFormat.SampleRate;

            int bitPerSample = reader.WaveFormat.BitsPerSample;

            const int BUFFER_SIZE = 1024 * 16;

            SoundStretcher stretcher = new SoundStretcher(sampleRate, numChannels);
            WaveFileWriter writer = new WaveFileWriter(fileOut, new WaveFormat(sampleRate, 16, numChannels));

            stretcher.Tempo = newTempo;
            stretcher.Pitch = newPitch;
            stretcher.Rate = newRate;

            byte[] buffer = new byte[BUFFER_SIZE];
            short[] buffer2 = null;

            if (bitPerSample != 16 && bitPerSample != 8)
            {
                throw new Exception("Not implemented yet.");
            }

            if (bitPerSample == 8)
            {
                buffer2 = new short[BUFFER_SIZE];
            }

            bool finished = false;

            while (true)
            {
                int bytesRead = 0;
                if (!finished)
                {
                    bytesRead = reader.Read(buffer, 0, BUFFER_SIZE);

                    if (bytesRead == 0)
                    {
                        finished = true;
                        stretcher.Flush();
                    }
                    else
                    {
                        if (bitPerSample == 16)
                        {
                            stretcher.PutSamplesFromBuffer(buffer, 0, bytesRead);
                        }
                        else if (bitPerSample == 8)
                        {
                            for (int i = 0; i < BUFFER_SIZE; i++)
                                buffer2[i] = (short)((buffer[i] - 128) * 256);
                            stretcher.PutSamples(buffer2);
                        }
                    }
                }
                bytesRead = stretcher.ReceiveSamplesToBuffer(buffer, 0, BUFFER_SIZE);
                writer.Write(buffer, 0, bytesRead);

                if (finished && bytesRead == 0)
                    break;
            }

            reader.Close();
            writer.Close();
        }
开发者ID:michaelbehner96,项目名称:Xyzzxyz,代码行数:73,代码来源:Utilities.cs

示例4: ConvertSample

        XSample ConvertSample(int count, SSampleHeader sh, byte [] sample, Zone izone)
        {
            // Indices in sf2 are numbers of samples, not byte length. So double them.
            var xs = new XSample ();
            xs.Extension = ".wav";
            xs.LoopStart =(sh.StartLoop - sh.Start);
            xs.LoopEnd = (sh.EndLoop - sh.Start);
            int sampleModes = izone.SampleModes ();
            xs.LoopMode = sampleModes == 0 ? InstrumentSampleLoopMode.Off : InstrumentSampleLoopMode.Forward;
            xs.Name = String.Format ("Sample{0:D02} ({1})", count, sh.SampleName);
            xs.BaseNote = (sbyte) izone.OverridingRootKey ();
            //			xs.Volume = (izone.VelocityRange () & 0xFF00 >> 8); // low range
            if (xs.BaseNote == 0)
                xs.BaseNote = (sbyte) sh.OriginalPitch;
            //Console.WriteLine ("{0} ({1}/{2}/{3}/{4}) {5}:{6}:{7}:{8}", xs.Name, sh.Start, sh.StartLoop, sh.EndLoop, sh.End, sh.SampleRate != 0xAC44 ? sh.SampleRate.ToString () : "", sh.OriginalPitch != 60 ? sh.OriginalPitch.ToString () : "", sh.PitchCorrection != 0 ? sh.PitchCorrection.ToString () : "", sampleModes);
            xs.FileName = xs.Name + ".wav";
            var ms = new MemoryStream ();
            var wfw = new WaveFileWriter (ms, new WaveFormat ((int) sh.SampleRate, 16, 1));
            wfw.WriteData (sample, 2 * (int) sh.Start, 2 * (int) (sh.End - sh.Start));
            wfw.Close ();
            xs.Buffer = ms.ToArray ();

            return xs;
        }
开发者ID:zeromus,项目名称:sf2xrni,代码行数:24,代码来源:sf2xrni.cs

示例5: ExportWAVBtnClick

 void ExportWAVBtnClick(object sender, EventArgs e)
 {
     if(saveFileDialog1.ShowDialog() == DialogResult.OK) {
         byte[] buf = MakeByteBuf();
         WaveFileWriter wfw = new WaveFileWriter(saveFileDialog1.FileName, new WaveFormat(samplingRate, 8, 1));
         wfw.WriteData(buf, 0, buf.Length);
         wfw.Close();
     }
 }
开发者ID:akx,项目名称:fxfxfx,代码行数:9,代码来源:MainForm.cs

示例6: ButtonSave_Click

        private void ButtonSave_Click(object sender, EventArgs e)
        {
            this.buttonPause.Enabled = false;
            this.buttonStart.Enabled = false;
            this.buttonStop.Enabled = false;
            this.buttonNewEvent.Enabled = false;
            this.buttonClear.Enabled = false;
            this.buttonSave.Enabled = false;

            WaveFileWriter writer = new WaveFileWriter(this.testName + ".wav", this.waveFormat);
            foreach(DataRow row in dataSet.WaveTable.Rows)
            {
                writer.WriteByte((byte)row["Amplitude"]);
            }
            writer.Close();

            var result = new StringBuilder();
            for (int i = 0; i < dataSet.WaveTable.Columns.Count; i++)
            {
                result.Append(dataSet.WaveTable.Columns[i].ColumnName);
                result.Append(i == dataSet.WaveTable.Columns.Count - 1 ? "\n" : ",");
            }

            foreach (DataRow row in dataSet.WaveTable.Rows)
            {
                for (int i = 0; i < dataSet.WaveTable.Columns.Count; i++)
                {
                    result.Append(row[i].ToString());
                    result.Append(i == dataSet.WaveTable.Columns.Count - 1 ? "\n" : ",");
                }
            }

            StreamWriter waveData = System.IO.File.CreateText(this.testName + "-wave.csv");
            waveData.Write(result.ToString());
            waveData.Close();

            result = new StringBuilder();
            for (int i = 0; i < dataSet.EventTable.Columns.Count; i++)
            {
                result.Append(dataSet.EventTable.Columns[i].ColumnName);
                result.Append(i == dataSet.EventTable.Columns.Count - 1 ? "\n" : ",");
            }

            foreach (DataRow row in dataSet.EventTable.Rows)
            {
                for (int i = 0; i < dataSet.EventTable.Columns.Count; i++)
                {
                    result.Append(row[i].ToString());
                    result.Append(i == dataSet.EventTable.Columns.Count - 1 ? "\n" : ",");
                }
            }

            StreamWriter eventData = System.IO.File.CreateText(this.testName + "-event.csv");
            eventData.Write(result.ToString());
            eventData.Close();

            this.buttonPause.Enabled = false;
            this.buttonStart.Enabled = true;
            this.buttonStop.Enabled = false;
            this.buttonNewEvent.Enabled = false;
            this.buttonClear.Enabled = true;
            this.buttonSave.Enabled = false;
        }
开发者ID:Sensco,项目名称:TestRunner,代码行数:63,代码来源:RecordForm.cs

示例7: WordToWAV


//.........这里部分代码省略.........
                        {
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency);
                            Thread.Sleep(dash);
                        }

                        if (symbol == '\'')
                        {
                            WavPlay(writer, dot, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dash, amplitude, frequency); WavPause(writer, dot);
                            WavPlay(writer, dot, amplitude, frequency);
                            Thread.Sleep(dash);
                        }

                    } // End For j

                    if (non_random_flag)
                    {
                        screen_Out(word);               // вывод на label непрерывно
                    }
                    else
                    {
                        screen_Out_By_10(i, word);      // вывод на label по 10 слов
                    }

                    int dynamic_interval = 1;          // Длительность динамического интервала между словами
                    if (dynamic_interval_flag)
                    {
                        dynamic_interval = word.Length;
                    }

                    WavPause(writer, interval * dash * dynamic_interval);  // Пауза между словами

                } // End for(i)

                writer.Close();
                writer.Dispose();

            } // end using

            // Конвертим WAV-файл в MP3-файл
            if (File.Exists(fileName + ".wav"))
                ConvertWavToMP3(fileName);
            else
            {
                if (english_flag)
                    MessageBox.Show("No exist WAV-file to conver in MP3.");
                else
                    MessageBox.Show(fileName + ".wav ", "Нет WAV-файла для конвертации в MP3.");
            }
            // Переместить звуковые файлы
            if (alternative_mp3_flag)
            {
                try
                {
                    // MessageBox.Show("Конвертим с задержкой MP3.");
                    // Не успевает LAME отрабоать - заддерка нужна
                    Thread.Sleep(5000);     // 5 секунд

                    if (File.Exists(fileName + ".mp3"))
                    {
                        // Удаляем старые файлы
                        if (File.Exists(fileNameOld + ".mp3 "))
                            File.Delete(fileNameOld + ".mp3 ");

                        //Переносим файлы из корня диска в папку, указанную пользователем
                        File.Move(fileName + ".mp3 ", fileNameOld + ".mp3");
                    }
                    else
                        MessageBox.Show(fileName + ".mp3 ", "Нет MP3-файла!");

                    if (File.Exists(fileName + ".wav"))
                    {
                        //MessageBox.Show(fileName + ".wav ", "Старый файл WAV");
                        //MessageBox.Show(fileNameOld + ".wav ", "Новый файл WAV");
                       // MessageBox.Show(fileName + ".mp3 ", "Старый файл MP3");
                       // MessageBox.Show(fileNameOld + ".mp3 ", "Новый файл MP3");

                        // Удаляем старые файлы
                        if (File.Exists(fileNameOld + ".wav "))
                            File.Delete(fileNameOld + ".wav ");

                        //Переносим файлы из корня диска в папку, указанную пользователем
                        File.Move(fileName + ".wav ", fileNameOld + ".wav");
                    }

                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "The process move a audiofiles failed!");
                }
            }
        }
开发者ID:richmanfx,项目名称:cw_win_4,代码行数:101,代码来源:Cw_winForm.cs

示例8: waveIn_RecordingStopped

        private void waveIn_RecordingStopped(object sender, EventArgs e)
        {
            if (writeToFile == 1)
            {
                waveIn.Dispose();
                waveIn = null;
                writer.Close();
                writer = null;

                int bytes_to_read = (rec_times + 1) * 6400;
                byte[] wav_bytes = new byte[bytes_to_read];

                WaveFileReader wfr = new WaveFileReader("file.wav");

                if (wfr.Length < bytes_to_read)
                {
                    wfr.Read(wav_bytes, 0, (int)wfr.Length);
                }
                else
                {
                    wfr.Position = wfr.Length - 1 - bytes_to_read;
                    wfr.Read(wav_bytes, 0, bytes_to_read);

                }
                wfr.Dispose();
                wfr.Close();

                WaveIn second_waveIn = new WaveIn();
                second_waveIn.DeviceNumber = 0;
                second_waveIn.WaveFormat = new WaveFormat(16000, 2);
                WaveFileWriter second_writer = new WaveFileWriter("cmd.wav", second_waveIn.WaveFormat);
                second_waveIn.StartRecording();
                second_writer.Write(wav_bytes, 0, bytes_to_read);
                second_waveIn.StopRecording();

                second_waveIn.Dispose();
                second_waveIn = null;
                second_writer.Close();
                second_writer = null;

                listBox1.Items.Add("CONVERTING");
                listBox1.SelectedIndex = listBox1.Items.Count - 1;

                Wav2Flac("cmd.wav", "file.flac");

                result = GoogleSpeechRequest(16000);
                string res = result;
                int k = res.IndexOf("utterance\":\"") + "utterance\":\"".Length;
                int k1 = res.IndexOf("\"", k + 1);
                string cmd = res.Substring(k, k1 - k);
                listBox1.Items.Add("RECOGNIZED");
                richTextBox1.Text += cmd + "\n";

                File.Delete("cmd.wav");
                rec_times = 0;
                writeToFile = 0;
            }
            else

                if (writeToFile == 0)
                {
                    waveIn.Dispose();
                    waveIn = null;
                    writer.Close();
                    writer = null;
                }
        }
开发者ID:Alyasko,项目名称:ComputerSpeechControl,代码行数:67,代码来源:Form1.cs

示例9: recordInput

        //Microphone.
        //http://mark-dot-net.blogspot.com/2011/04/how-to-use-wavefilewriter.html
        public void recordInput()
        {
            Console.WriteLine("Now recording...");
            waveSource = new WaveInEvent();
            waveSource.WaveFormat = new WaveFormat(16000, 1);

            waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
            waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);
            //string tempFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".wav");
            string tempFile = Path.Combine(@"C:\Users\Nick\Desktop",  "test.wav");
            waveFile = new WaveFileWriter(tempFile, waveSource.WaveFormat);
            waveSource.StartRecording();

            Thread.Sleep(3000);
            waveSource.StopRecording();
            waveSource.Dispose();
            waveSource = null;
            waveFile.Close();

            Console.WriteLine("Finished record");
        }
开发者ID:konecnyna,项目名称:Jarvis,代码行数:23,代码来源:GoogleVoice.cs

示例10: GetWaveDataStream

        private static byte[] GetWaveDataStream(string mlvFileName)
        {
            MLVCachedReader cache = GetReader(mlvFileName);
            Stream mem = new MemoryStream();
            MLVTypes.mlv_wavi_hdr_t header = cache.handler.WaviHeader;

            WaveFormat fmt = new WaveFormat((int)header.samplingRate, header.bitsPerSample, header.channels);
            cache.handler.WaveProvider = new BufferedWaveProvider(fmt);
            cache.handler.WaveProvider.BufferLength = 20 * 1024 * 1024;

            WaveFileWriter wr = new WaveFileWriter(mem, fmt);

            lock (cache)
            {
                foreach (var frame in cache.reader.AudfXrefList.Keys)
                {
                    /* seek to the correct block */
                    cache.reader.CurrentBlockNumber = cache.reader.GetAudioFrameBlockNumber(frame);
                    cache.handler.AudfHeader.blockSize = 0;
                    cache.reader.ReadBlock();

                    /* now the VIDF should be read correctly */
                    if (cache.handler.AudfHeader.blockSize == 0)
                    {
                        throw new InvalidDataException("Requested audio frame " + frame + " but the index points us wrong");
                    }

                    /* save into wave file stream */
                    byte[] data = new byte[cache.handler.WaveProvider.BufferedBytes];
                    cache.handler.WaveProvider.Read(data, 0, data.Length);
                    wr.Write(data, 0, data.Length);
                }
            }

            mem.Seek(0, SeekOrigin.Begin);

            byte[] buffer = new byte[mem.Length];
            mem.Read(buffer, 0, buffer.Length);

            mem.Close();
            wr.Close();

            return buffer;
        }
开发者ID:HulaSamsquanch,项目名称:1100d_lantern,代码行数:44,代码来源:MLVAccessor.cs

示例11: Wav2Flac

        private byte[] Wav2Flac(MemoryStream waveStreamMemory)
        {
            if (waveStreamMemory.Length >= 3200) // 0
            {
                Log.Write("Ева услышала Вас.", Log.Category.Information);
                byte[] Array = null;

                WaveFileWriter writer = new WaveFileWriter("C:\\rec_temp.wav", waveInEvent.WaveFormat);
                writer.Write(waveStreamMemory.ToArray(), 0, waveStreamMemory.ToArray().Length);
                writer.Close();

                IAudioSource audioSource = new WAVReader("C:\\rec_temp.wav", null);
                AudioPCMConfig audioPCMConfig = new AudioPCMConfig(16, 1, 16000);

                AudioBuffer buff = new AudioBuffer(audioSource, 0x10000);
                //AudioBuffer buffMemory = new AudioBuffer(audioPCMConfig, waveStreamMemory.ToArray(), Convert.ToInt32(waveStreamMemory.Length) / audioPCMConfig.BlockAlign);

                FlakeWriter flakewriter = new FlakeWriter(null, audioSource.PCM);

                FlakeWriter audioDest = flakewriter;
                while (audioSource.Read(buff, -1) != 0)
                {
                    audioDest.Write(buff);
                }

                if (flakewriter.BufferMemory != null)
                {
                    Array = flakewriter.BufferMemory.ToArray();
                }

                audioDest.Close();
                audioSource.Close();

                return Array;
            }

            return null;
        }
开发者ID:kidinfo,项目名称:AI_Eva,代码行数:38,代码来源:Hearing.cs


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