コード例 #1
1
ファイル: NAudioTest.cs プロジェクト: kakapi/FuSrv
 public void NAudioDurationTest()
 {
     string duration;
     NAudio.Wave.WaveFileReader wf = new NAudio.Wave.WaveFileReader(Environment.CurrentDirectory + @"\testfiles\GAudio_Receive4.wav");
     TimeSpan tp = wf.TotalTime;
     duration = tp.TotalSeconds.ToString();
     Console.WriteLine(duration);
 }
コード例 #2
0
ファイル: MyMusic.xaml.cs プロジェクト: Ilmefy/MusicPlayer
        private double GetLengthToDouble(string Path)
        {
            NAudio.Wave.Mp3FileReader  mp3FileReader;
            NAudio.Wave.WaveFileReader waveFileReader;
            TimeSpan timeSpan = new TimeSpan();

            try
            {
                if (System.IO.Path.GetExtension(Path) == ".mp3")
                {
                    mp3FileReader = new NAudio.Wave.Mp3FileReader(Path);
                    timeSpan      = mp3FileReader.TotalTime;
                    mp3FileReader.Dispose();
                }
                if (System.IO.Path.GetExtension(Path) == ".wav")
                {
                    waveFileReader = new NAudio.Wave.WaveFileReader(Path);
                    waveFileReader.Dispose();
                    timeSpan = waveFileReader.TotalTime;
                }
                return(timeSpan.TotalSeconds);
            }
            catch (Exception)
            {
                return(0.0d);
            }
        }
コード例 #3
0
ファイル: Utils.cs プロジェクト: AlexS4v/ORB4
        public static async void PlayWavAsync(byte[] bytes)
        {
            try
            {
                using (MemoryStream stream = new MemoryStream(bytes))
                {
                    using (NAudio.Wave.WaveOutEvent waveOut = new NAudio.Wave.WaveOutEvent())
                    {
                        using (var reader = new NAudio.Wave.WaveFileReader(stream))
                        {
                            waveOut.Init(reader);
                            waveOut.Play();

                            while (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                            {
                                await Task.Delay(1);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.MainLogger.Log(Logger.LogTypes.Error, e.ToString());
            }
        }
コード例 #4
0
        private void readDataAndDraw()
        {
            short[] data = null;
            NAudio.Wave.WaveStream reader = null;
            if (t.Format.Equals("MP3"))
            {
                reader = new NAudio.Wave.Mp3FileReader(t.Path);
            }
            else if (t.Format.Equals("WAV"))
            {
                reader = new NAudio.Wave.WaveFileReader(t.Path);
            }
            if (reader != null)
            {
                byte[] buffer = new byte[reader.Length];
                int    read   = reader.Read(buffer, 0, buffer.Length);
                data = new short[read / sizeof(short)];
                Buffer.BlockCopy(buffer, 0, data, 0, read);
            }
            List <short> chan1 = new List <short>();
            List <short> chan2 = new List <short>();

            for (int i = 0; i < data.Length - 1; i += 2)
            {
                chan1.Add(data[i]);
                chan2.Add(data[i + 1]);
            }
            plot(chan1.ToArray());
        }
コード例 #5
0
        //allows the user to playback recorded .wav files or use it as a media player
        private void openFileBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Wave File (*.wav)|*.wav;";
            if (open.ShowDialog() != DialogResult.OK) return;
            filePathLbl.Text = open.FileName;
            DisposeWave(); //clears the wavefilereader of any previous contents and disposes of the waveout device

            // sets the wavefile reader and waveout up afresh using the contents of the newly selected file
            wFileReader = new NAudio.Wave.WaveFileReader(open.FileName); 
            waveOut = new NAudio.Wave.DirectSoundOut();
            waveOut.Init(new NAudio.Wave.WaveChannel32(wFileReader));

            //The rest of this method was an attempt at creating a waveViewer object in the large open white space using a graph
            // to plot the points of each sample.

            //NAudio.Wave.WaveChannel32 wave = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName));
            //automatically converts format to get 32bit floating point number of wave file

            //converts from byte array to a floating pint number
            //byte[] buffer = new byte[16384]; //read 16kb at a time from wav file
            //int read = 0; //number of bytes read

            //while (wave.Position < wave.Length) //do until end of wave file
            //{
            //    read = wave.Read(buffer, 0, 16384); //reading from byte buffer, from beginning, read all bytes in buffer
            //    for (int i = 0; i < read / 4; i++) // 4 bytes per floating point number
            //    {
            //     //   waveViewChart.Series["wave"].Points.Add(BitConverter.ToSingle(buffer, i * 4)); 
            //        //add point to chart from converted bit to 32bit floating point number
            //        //uses the buffer as byte array and 1 * 4 as the index point from buffer in which to read
            //    }
            //}
        }
コード例 #6
0
ファイル: Audio.cs プロジェクト: BSalita/Woundify
 public static async System.Threading.Tasks.Task <int> GetSampleRateAsync(string fileName) // todo: need "byte[] bytes" overload
 {
     using (NAudio.Wave.WaveFileReader file = new NAudio.Wave.WaveFileReader(fileName))
     {
         return(file.WaveFormat.SampleRate);
     }
 }
コード例 #7
0
            private void OpenWaveFile(out int Sample_Freq, out double[] SignalETC)
            {
                NAudio.Wave.WaveFileReader WP = new NAudio.Wave.WaveFileReader(Signal_Status.Text);

                int BytesPerSample  = WP.WaveFormat.Channels * WP.WaveFormat.BitsPerSample / 8;
                int BytesPerChannel = WP.WaveFormat.BitsPerSample / 8;

                byte[] signalbuffer = new byte[BytesPerSample];
                int    ChannelCt    = WP.WaveFormat.Channels;

                Sample_Freq = WP.WaveFormat.SampleRate;
                double[] SignalInt = new double[WP.SampleCount];

                if (WP.WaveFormat.BitsPerSample == 8)
                {
                    System.Windows.Forms.MessageBox.Show("Selected File is an 8-Bit audio file. This program requires a minimum bit-depth of 16.");
                    SignalETC = new double[SignalInt.Length];
                    return;
                }
                byte[] temp = new byte[4];
                int    c    = (int)DryChannel.Value - 1;

                for (int i = 0; i < WP.SampleCount; i++)
                {
                    WP.Read(signalbuffer, 0, BytesPerSample);

                    if (WP.WaveFormat.BitsPerSample == 32)
                    {
                        SignalInt[i] = BitConverter.ToInt32(signalbuffer, c * 4);
                    }
                    else if (WP.WaveFormat.BitsPerSample == 24)
                    {
                        temp[1]      = signalbuffer[c * BytesPerChannel];
                        temp[2]      = signalbuffer[c * BytesPerChannel + 1];
                        temp[3]      = signalbuffer[c * BytesPerChannel + 2];
                        SignalInt[i] = BitConverter.ToInt32(temp, 0);
                    }
                    else if (WP.WaveFormat.BitsPerSample == 16)
                    {
                        temp[2]      = signalbuffer[c * BytesPerChannel];
                        temp[3]      = signalbuffer[c * BytesPerChannel + 1];
                        SignalInt[i] = BitConverter.ToInt32(temp, 0);
                    }
                }

                SignalETC = new double[SignalInt.Length];

                double Max = double.NegativeInfinity;

                for (int i = 0; i < SignalInt.Length; i++)
                {
                    Max = Math.Max(Max, Math.Abs(SignalInt[i]));
                }

                for (int i = 0; i < SignalInt.Length; i++)
                {
                    SignalETC[i] = SignalInt[i] / Max;
                }
                SignalETC = SignalInt;
            }
コード例 #8
0
        // function to check a valid hit in the program
        private void CheckForAHit()
        {
            Image <Gray, byte> temp;

            for (int i = 0; i < NumberOfBalls; i++)
            {
                temp = Balls[i].And(DifferenceFrame);
                temp = temp.ThresholdBinary(new Gray(240), new Gray(255));
                int number = temp.CountNonzero()[0];

                if (number != 0)
                {
                    MCvFont font      = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_DUPLEX, 1d, 1d);
                    MCvFont fontSmall = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, .25d, .5d);
                    NumberOfHits++;
                    Score++;
                    bomb = new NAudio.Wave.WaveFileReader(Constants.BOMB_EXPLOSION_FILE_LOC);

                    //TODO: move the initlization out and make sure that only once the init happens
                    output = new NAudio.Wave.DirectSoundOut();
                    output.Init(new NAudio.Wave.WaveChannel32(bomb));
                    Random r = new Random();
                    InputImageFrame.Draw(new CircleF(new PointF(XYCoordinatesOfBalls[i, 0], XYCoordinatesOfBalls[i, 1]), 10), new Bgr(r.Next(0, 255), 0, 255), 50);

                    InputImageFrame.Draw("Hit", ref font, new Point(XYCoordinatesOfBalls[i, 0] - 20, XYCoordinatesOfBalls[i, 1] + 10), new Bgr(Color.White));
                    generateXYCoordiantesForBall(i);
                }
            }
            if (output != null)
            {
                output.Play();
            }
        }
コード例 #9
0
        public void PlayStream(Stream stream, bool wait, bool closeStream)
        {
            stream.Position = 0;

            if (wait)
            {
                NAudio.Wave.WaveFileReader wfr = new NAudio.Wave.WaveFileReader(stream);
                NAudio.Wave.WaveOutEvent   wo  = new NAudio.Wave.WaveOutEvent();
                wo.DeviceNumber = dev;
                if (vol != -1)
                {
                    wo.Volume = vol;
                }
                wo.Init(wfr);
                wo.Play();
                while (wo.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                {
                    System.Threading.Thread.Sleep(10);
                }
                if (closeStream)
                {
                    wfr.Close();
                    stream.Close();
                    stream = null;
                }
                ;
            }
            else
            {
                System.Threading.Thread thr = new System.Threading.Thread(Play);
                thr.Start(new object[] { stream, closeStream });
            };
        }
コード例 #10
0
        public void PlayFile(string filename, bool wait)
        {
            FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read);

            if (wait)
            {
                NAudio.Wave.WaveFileReader wfr = new NAudio.Wave.WaveFileReader(stream);
                NAudio.Wave.WaveOutEvent   wo  = new NAudio.Wave.WaveOutEvent();
                wo.DeviceNumber = dev;
                if (vol != -1)
                {
                    wo.Volume = vol;
                }
                wo.Init(wfr);
                wo.Play();
                while (wo.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                {
                    System.Threading.Thread.Sleep(10);
                }
                wfr.Close();
                stream.Close();
            }
            else
            {
                System.Threading.Thread thr = new System.Threading.Thread(Play);
                thr.Start(new object[] { stream, true });
            };
        }
コード例 #11
0
        private void Play(object stream_close)
        {
            object[] strmcls     = (object[])stream_close;
            Stream   stream      = (Stream)strmcls[0];
            bool     closeStream = (bool)strmcls[1];

            NAudio.Wave.WaveFileReader wfr = new NAudio.Wave.WaveFileReader(stream);
            NAudio.Wave.WaveOutEvent   wo  = new NAudio.Wave.WaveOutEvent();
            wo.DeviceNumber = dev;
            if (vol != -1)
            {
                wo.Volume = vol;
            }
            wo.Init(wfr);
            wo.Play();
            while (wo.PlaybackState == NAudio.Wave.PlaybackState.Playing)
            {
                System.Threading.Thread.Sleep(10);
            }
            if (closeStream)
            {
                wfr.Close();
                stream.Close();
                stream = null;
            }
            ;
        }
コード例 #12
0
        private void txtB_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Return)
            {
                clearWave();
                SpeechSynthesizer synth = new SpeechSynthesizer();

                synth.SelectVoice(cBox.SelectedItem.ToString());
                synth.Rate = (int)slider.Value;
                synth.SetOutputToWaveFile(wFile);
                synth.Speak(txtB.Text);
                synth.SetOutputToNull();

                File.Copy(wFile, wFile2, true);

                waveReader     = new NAudio.Wave.WaveFileReader(wFile);
                waveReaderToMe = new NAudio.Wave.WaveFileReader(wFile2);

                waveOut  = new NAudio.Wave.WaveOut(); //for playing to selected device
                waveToMe = new NAudio.Wave.WaveOut(); //for playback to user through default device

                waveOut.DeviceNumber = deviceComboBox.SelectedIndex;

                waveOut.Init(waveReader);
                waveOut.Play();

                waveToMe.Init(waveReaderToMe);
                waveToMe.Play();

                txtB.Text = "";
            }
        }
コード例 #13
0
 private void clearWave()
 {
     if (waveOut != null && waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing)
     {
         waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (waveToMe != null && waveToMe.PlaybackState == NAudio.Wave.PlaybackState.Playing)
     {
         waveToMe.Stop();
         waveToMe.Dispose();
         waveToMe = null;
     }
     if (waveReader != null)
     {
         waveReader.Dispose();
         waveReader = null;
     }
     if (waveReaderToMe != null)
     {
         waveReaderToMe.Dispose();
         waveReaderToMe = null;
     }
 }
コード例 #14
0
 private void Musice2()
 {
     Chaikovsky = new NAudio.Wave.WaveFileReader("BOOM.wav");
     Borodin    = new NAudio.Wave.DirectSoundOut();
     Borodin.Init(new NAudio.Wave.WaveChannel32(Chaikovsky));
     Borodin.Play();
 }
コード例 #15
0
 private void pictureBox3_Click(object sender, EventArgs e)
 {
     DisposeAll();
     wave   = new NAudio.Wave.WaveFileReader(Path);
     player = new NAudio.Wave.DirectSoundOut();
     player.Init(new NAudio.Wave.WaveChannel32(wave));
     player.Play();
 }
コード例 #16
0
 private void initReader(String backgroundSoundName)
 {
     if (this.reader != null)
     {
         this.reader.Dispose();
     }
     this.reader      = new NAudio.Wave.WaveFileReader(Path.Combine(backgroundFilesPath, backgroundSoundName));
     backgroundLength = reader.TotalTime;
 }
コード例 #17
0
        private void dumpButton_Click(object sender, EventArgs e)
        {
            if (!validateWavFilename())
            {
                return;
            }

            Application.DoEvents();

            using (NAudio.Wave.WaveFileReader waveFile = new NAudio.Wave.WaveFileReader(wavFilenameTextBox.Text))
            {
                tapFile = new TapFile();

                WaveSeeker waveSeeker = new WaveSeeker(waveFile);

                infoTextBox.Clear();
                // Read Header Information
                if (!readHeaderInfo(waveSeeker))
                {
                    return;
                }

                byte theByte = 0;

                short  counter     = 0;
                string charVersion = "";

                // while not eof...
                while (waveSeeker.readByte(out theByte))
                {
                    infoTextBox.AppendText(theByte.ToString("X2") + " ");
                    charVersion += printableChar((char)theByte);
                    if (counter == 7)
                    {
                        infoTextBox.AppendText(" " + charVersion + Environment.NewLine);
                        charVersion = "";
                        counter     = 0;
                    }
                    else
                    {
                        counter++;
                    }
                }

                // Formatting...
                while (counter < 8)
                {
                    infoTextBox.AppendText("   ");
                    counter++;
                }

                if (charVersion != "")
                {
                    infoTextBox.AppendText(" " + charVersion + Environment.NewLine + Environment.NewLine);
                }
            }
        }
コード例 #18
0
        static void Main(string[] args)
        {
            try
            {
                //var file = new NAudio.Wave.WaveFileReader("pocsag-short-2400.wav");
                //var file = new NAudio.Wave.WaveFileReader("SDRSharp_20210407_174912Z_153350000Hz_AF.wav");
                var file = new NAudio.Wave.WaveFileReader("POCSAG500_interference_tonyp.wav");

                var samples = new List <float>();

                while (true)
                {
                    var frame = file.ReadNextSampleFrame();

                    if (frame == null)
                    {
                        break;
                    }

                    samples.Add(frame[0]);
                }

                var decodes = 0;

                var pocsagManager =
                    new Manager(
                        file.WaveFormat.SampleRate,
                        (PocsagMessage message) =>
                {
                    if (!message.IsValid)
                    {
                        return;
                    }

                    Console.Write($"{message.Bps} {message.ErrorsCorrected} ");
                    Console.WriteLine(message.Payload);

                    decodes++;
                });

                foreach (var sample in samples)
                {
                    pocsagManager.Process(sample);
                }

                Console.WriteLine($"Decodes: {decodes}");
            }
            catch (Exception exception)
            {
                Log.LogException(exception);
                Console.WriteLine($"Exception: {exception.Message}");
            }

            Console.WriteLine("Done.");
            Console.ReadKey(true);
        }
コード例 #19
0
        //Plays/Repeats the audio of the letter
        private void repeatBtn_Click(object sender, EventArgs e)
        {
            String filename = "Class" + LoginForm.classSec + "_kidAudio/" + letters[curPos] + ".wav";

            DisposeWave();

            wave   = new NAudio.Wave.WaveFileReader(filename);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
コード例 #20
0
        private void jollyPicBox_Click(object sender, EventArgs e)
        {
            string file = "Class" + LoginForm.classSec + "_kidAudio/" + lvlStr.ToLower() + ".wav";

            DisposeWave();

            wave   = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
コード例 #21
0
        public void ProduceFullAudioClipData(FullAudioClipData fullAudioClipData)
        {
            string            ResourcesRootDirectory = BmsChartFolder;
            BmsAudioGenerator bmsAudioGenerator      = new BmsAudioGenerator(44100, 2);
            int TotalCount  = NativeBmsChart.Events.Count;
            int LoadedCount = 0;

            foreach (BMSEvent Event in NativeBmsChart.Events)
            {
                switch (Event.type)
                {
                case BMSEventType.LongNoteEnd:
                case BMSEventType.LongNoteStart:
                case BMSEventType.Note:
                case BMSEventType.WAV:
                    BMSResourceData resourceData = new BMSResourceData();
                    if (!NativeBmsChart.TryGetResourceData(ResourceType.wav, Event.data2, out resourceData))
                    {
                        continue;
                    }
                    string FileName        = Path.GetFileNameWithoutExtension(resourceData.dataPath);
                    string OggResourcePath = (ResourcesRootDirectory + "/" + FileName + ".ogg").Replace("\\", "/");
                    string WavResourcePath = (ResourcesRootDirectory + "/" + FileName + ".wav").Replace("\\", "/");
                    if (File.Exists(OggResourcePath))
                    {
                        NVorbis.VorbisReader vorbisReader = new NVorbis.VorbisReader(OggResourcePath);
                        float[] oggData = new float[vorbisReader.TotalSamples * vorbisReader.Channels];
                        vorbisReader.ReadSamples(oggData, 0, (int)(vorbisReader.TotalSamples * vorbisReader.Channels));
                        bmsAudioGenerator.PutAudioAt((float)Event.time.TotalSeconds, oggData);
                    }
                    else if (File.Exists(WavResourcePath))
                    {
                        List <float> wavData = new List <float>();
                        NAudio.Wave.WaveFileReader waveFileReader = new NAudio.Wave.WaveFileReader(WavResourcePath);
                        float[] wavFrame;
                        while (true)
                        {
                            wavFrame = waveFileReader.ReadNextSampleFrame();
                            if (wavFrame == null)
                            {
                                break;
                            }
                            wavData.AddRange(wavFrame);
                        }
                        bmsAudioGenerator.PutAudioAt((float)Event.time.TotalSeconds, wavData.ToArray());
                    }
                    break;
                }
                LoadedCount++;
                fullAudioClipData.Percent = 100f * LoadedCount / TotalCount;
            }
            fullAudioClipData.Data        = bmsAudioGenerator.Data;
            fullAudioClipData.IsCompleted = true;
        }
コード例 #22
0
        private void jollyPicBox_Click_1(object sender, EventArgs e)
        {
            string file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\TeacherWAV\" + lvlStr.ToLower() + ".wav";

            DisposeWave();

            wave   = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: Ramsau/Artsy-Stuff
 static void Main(string[] args)
 {
     NAudio.Wave.WaveFileReader wave = new NAudio.Wave.WaveFileReader(@"C:\Users\Christoph Royer\Documents\Visual Studio 2017\Projects\Artsy Stuff\Audioframe\bin\Debug\Rick Astley - Never Gonna Give You Up.wav");
     wave.Skip(30);
     for (int i = 0; i < 5000; i++)
     {
         float[] frame = wave.ReadNextSampleFrame();
         Console.WriteLine(frame[0]);
     }
     Console.ReadLine();
 }
コード例 #24
0
 private void OpenSignal_Click(object sender, System.EventArgs e)
 {
     GetWave.Filter = " Wave Audio (*.wav) |*.wav";
     if (GetWave.ShowDialog() == DialogResult.OK)
     {
         Signal_Status.Text = GetWave.FileName;
         RenderBtn.Enabled  = true;
         NAudio.Wave.WaveFileReader WR = new NAudio.Wave.WaveFileReader(Signal_Status.Text);
         DryChannel.Minimum = 1;
         DryChannel.Maximum = WR.WaveFormat.Channels;
     }
 }
コード例 #25
0
 // Abertura do arquivo
 private void bt_Abrir_Click(object sender, EventArgs e)
 {
     open        = new OpenFileDialog();
     open.Filter = "Wave File (*.wav)|*.wav;";
     if (open.ShowDialog() != DialogResult.OK)
     {
         return;
     }
     reader        = new NAudio.Wave.WaveFileReader(open.FileName);
     tam_arq_vetor = reader.Length;
     _reader_freq  = reader.WaveFormat.SampleRate;
     _reader_bit   = reader.WaveFormat.BitsPerSample;
 }
コード例 #26
0
    private void PlaySound(int deviceID, int soundID)
    {
        // I don't have the NAudio library so I can't check if it works or no though.
        disposeWave();
        NAudio.Wave.WaveFileReader waveReader = new NAudio.Wave.WaveFileReader(this._soundFilepaths[soundID]);
        var waveOut = new NAudio.Wave.WaveOut();

        waveOut.DeviceNumber = deviceNumber;
        var output = waveOut;

        output.Init(waveReader);
        output.Play();
    }
コード例 #27
0
        private void onKeyDown(object sender, KeyEventArgs e)
        {
            if (modActive == true)
            {
                // Sheathe / Unsheathe
                if (e.KeyCode == sheathe && !keyUp && !Game.Player.Character.IsSittingInVehicle())
                {
                    keyUp = true;

                    if (!spear.IsAttachedTo(Game.Player.Character))
                    {
                        spearActive = false;
                    }
                    else
                    {
                        spearActive = !spearActive;
                    }

                    // Sheathe
                    if (!spearActive)
                    {
                        spear.Detach();
                        unsheathed = false;

                        NAudio.Wave.WaveFileReader mp3whis1 = new NAudio.Wave.WaveFileReader(@"scripts\Spear Files\unsheathe.wav");
                        NAudio.Wave.WaveChannel32  waveDown = new NAudio.Wave.WaveChannel32(mp3whis1);
                        NAudio.Wave.DirectSoundOut output   = new NAudio.Wave.DirectSoundOut();
                        output.Init(waveDown);
                        output.Play();
                        waveDown.Volume = 0.05f;
                    }
                    else if (spear.IsAttachedTo(Game.Player.Character))
                    {
                        // Unsheathe
                        spear.AttachTo(Game.Player.Character, Game.Player.Character.GetBoneIndex(Bone.SKEL_Head),
                                       new Vector3(0.2f, 1, -0.2f),
                                       new Vector3(90, 0, 0)
                                       );

                        unsheathed = true;

                        NAudio.Wave.WaveFileReader recall  = new NAudio.Wave.WaveFileReader(@"scripts\Spear Files\return.wav");
                        NAudio.Wave.WaveChannel32  waveRec = new NAudio.Wave.WaveChannel32(recall);
                        NAudio.Wave.DirectSoundOut output3 = new NAudio.Wave.DirectSoundOut();
                        output3.Init(waveRec);
                        output3.Play();
                        waveRec.Volume = 0.05f;
                    }
                }
            }
        }
コード例 #28
0
ファイル: Form1.cs プロジェクト: AdroitProgrammer/Transcriber
        private void button2_Click(object sender, EventArgs e)
        {
            string newword   = textBox1.Text.Split('.')[0] + ".wav";
            var    inputfile = new MediaFile {
                Filename = textBox1.Text
            };
            var outputfile = new MediaFile {
                Filename = newword
            };

            audioPath = newword;

            using (var engine = new Engine())
            {
                engine.Convert(inputfile, outputfile);
            }

            NAudio.Wave.WaveFileReader reader = new NAudio.Wave.WaveFileReader(audioPath);
            currentMp3Duration = reader.TotalTime;
            reader.Dispose();

            DictationGrammar defaultDictationGrammar = new DictationGrammar();

            defaultDictationGrammar.Name    = "default dictation";
            defaultDictationGrammar.Enabled = true;

            DictationGrammar spellingDictationGrammar =
                new DictationGrammar("grammar:dictation#spelling");

            spellingDictationGrammar.Name    = "spelling dictation";
            spellingDictationGrammar.Enabled = true;

            DictationGrammar customDictationGrammar =
                new DictationGrammar("grammar:dictation");

            customDictationGrammar.Name    = "question dictation";
            customDictationGrammar.Enabled = true;

            _speechRecog.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(_speechRecog_SpeechRecognized);
            _speechRecog.SetInputToWaveFile(newword);
            _speechRecog.UpdateRecognizerSetting("CFGConfidenceRejectionThreshold", 80);
            _speechRecog.UpdateRecognizerSetting("HighConfidenceThreshold", 80);
            _speechRecog.UpdateRecognizerSetting("NormalConfidenceThreshold", 80);
            _speechRecog.UpdateRecognizerSetting("LowConfidenceThreshold", 80);
            _speechRecog.LoadGrammar(defaultDictationGrammar);
            _speechRecog.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(GetLines(Properties.Resources.Oxfords_3000_2)))));
            _speechRecog.LoadGrammar(spellingDictationGrammar);
            _speechRecog.LoadGrammar(customDictationGrammar);
            _speechRecog.RecognizeAsync(RecognizeMode.Multiple);
            _speechRecog.RecognizeCompleted += _speechRecog_RecognizeCompleted;
        }
コード例 #29
0
ファイル: Audio.cs プロジェクト: BSalita/Woundify
 public static async System.Threading.Tasks.Task PlayFileAsync(string fileName)
 {
     using (NAudio.Wave.WaveFileReader mic = new NAudio.Wave.WaveFileReader(fileName))
     {
         NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut();
         waveOut.DesiredLatency = Options.options.audio.NAudio.desiredLatencyMilliseconds;
         waveOut.Init(mic);
         waveOut.Play();
         while (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing)
         {
             System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(100)).Wait();
         }
     }
 }
コード例 #30
0
 private void DisposeWave()
 {
     if (waveOut != null)
     {
         if (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing) waveOut.Stop();
         waveOut.Dispose();
         waveOut = null;
     }
     if (wFileReader != null)
     {
         wFileReader.Dispose();
         wFileReader = null;
     }
 }
コード例 #31
0
        private void convert(string outputFile)
        {
#if UNITY_STANDALONE_WIN
            string tmpFile   = outputFile.Substring(0, outputFile.Length - 4) + "_" + SampleRate + Speaker.AudioFileExtension;
            bool   converted = false;

            try
            {
                using (var reader = new NAudio.Wave.WaveFileReader(outputFile))
                {
                    if (reader.WaveFormat.SampleRate != SampleRate)
                    {
                        var newFormat = new NAudio.Wave.WaveFormat(SampleRate, BitsPerSample, Channels);
                        using (var conversionStream = new NAudio.Wave.WaveFormatConversionStream(newFormat, reader))
                        {
                            NAudio.Wave.WaveFileWriter.CreateWaveFile(tmpFile, conversionStream);
                        }

                        converted = true;
                    }
                    //else
                    //{
                    //    Debug.Log("File ignored: " + outputFile);
                    //}
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Could not convert audio file: " + ex);
            }

            if (converted)
            {
                try
                {
                    if (!CreateCopy)
                    {
                        System.IO.File.Delete(outputFile);

                        System.IO.File.Move(tmpFile, outputFile);
                    }
                }
                catch (System.Exception ex)
                {
                    Debug.LogError("Could not delete and move audio files: " + ex);
                }
            }
#endif
        }
コード例 #32
0
        public void playTune(String result)
        {
            string file;
            if (result.Equals("WON"))
            {
                file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\happy.wav";
            }
            else
            {
                file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\sad.wav";
            }

            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
コード例 #33
0
ファイル: WaveFileHelper.cs プロジェクト: JoeGilkey/RadioLog
 public static void ProcessFile(string fileName)
 {
     try
     {
         string fileExt = System.IO.Path.GetExtension(fileName.ToLower());
         if (fileExt.Contains("mp3"))
         {
             using (NAudio.Wave.Mp3FileReader rdr = new NAudio.Wave.Mp3FileReader(fileName))
             {
                 //var newFormat = new NAudio.Wave.WaveFormat(48000, 16, 1);
                 var newFormat = new NAudio.Wave.WaveFormat(16000, 16, 1);
                 using (var conversionStream = new NAudio.Wave.WaveFormatConversionStream(newFormat, rdr))
                 {
                     if (System.IO.File.Exists("mdc1200tmp.wav"))
                         System.IO.File.Delete("mdc1200tmp.wav");
                     NAudio.Wave.WaveFileWriter.CreateWaveFile("mdc1200tmp.wav", conversionStream);
                 }
             }
         }
         else
         {
             using (NAudio.Wave.WaveFileReader rdr = new NAudio.Wave.WaveFileReader(fileName))
             {
                 var newFormat = new NAudio.Wave.WaveFormat(16000, 16, 1);
                 using (var conversionStream = new NAudio.Wave.WaveFormatConversionStream(newFormat, rdr))
                 {
                     if (System.IO.File.Exists("mdc1200tmp.wav"))
                         System.IO.File.Delete("mdc1200tmp.wav");
                     NAudio.Wave.WaveFileWriter.CreateWaveFile("mdc1200tmp.wav", conversionStream);
                 }
             }
         }
         using (NAudio.Wave.AudioFileReader rdr = new NAudio.Wave.AudioFileReader("mdc1200tmp.wav"))
         {
             ProcessProvider(rdr, fileName);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Process File Exception: {0}", ex.Message);
     }
 }
コード例 #34
0
 public static SerialPacketStream ReadAudioResource(string fileName, NAudio.Wave.WaveFormat format)
 {
     if (fileName.ToLower().EndsWith(".wav"))
     {
         var stream2 = App.GetResourceFileStream("MicActivate.wav");
         NAudio.Wave.WaveFileReader r = new NAudio.Wave.WaveFileReader(stream2);
         NAudio.Wave.ResamplerDmoStream s = new NAudio.Wave.ResamplerDmoStream(r, format);
         var length = (int)s.Length;
         byte[] resampled = new byte[length];
         s.Read(resampled, 0, length);
         var sps = new SerialPacketStream(resampled, format.SampleRate, fileName, 0, "self", false);
         return sps;
     }
     else if (fileName.ToLower().EndsWith(".pga"))
     {
         var stream = App.GetResourceFileStream("micTrigger.pga");
         var sps = SerialPacketStream.Read(stream);
         return sps;
     }
     else
     {
         throw new NotImplementedException();
     }
 }
コード例 #35
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            seconds = seconds - 1;
            if(seconds == 0)
            {
                stopProcess();
                questLabel.Text = "GAME OVER !";
                statusLabel.Text = "PRESS RESTART\nTO TRY AGAIN !";

                String file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\airhorn.wav";
                wave = new NAudio.Wave.WaveFileReader(file);
                output = new NAudio.Wave.DirectSoundOut();
                output.Init(new NAudio.Wave.WaveChannel32(wave));
                output.Play();

                MessageBox.Show("TIME'S UP !");
                MessageBox.Show("Total score: " + points);
            }
            timerLabel.Text = Convert.ToString(seconds);
        }
コード例 #36
0
        private void stopGame()
        {
            stopProcess();
            jumbledWordLabel.Text = "GAME OVER !";
            answerLabel.Text = "PRESS RESTART\nTO TRY AGAIN !";

            String file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\airhorn.wav";
            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();

            MessageBox.Show("TIME'S UP !");
            MessageBox.Show("Total score: " + points);
        }
コード例 #37
0
ファイル: Uploader.cs プロジェクト: kakapi/FuSrv
        public static bool ExtractInfo(string fileFullName, out string deviceno, out string duration)
        {
            deviceno = string.Empty;
            duration = string.Empty;
            string fileName = Path.GetFileName(fileFullName);
            string[] arr = fileName.Split('_');
            if (arr.Length != 2)
            {
                Logger.MyLogger.Info("文件名不符合规范,Skip." + fileName);
                return false;
            }
            deviceno = arr[0];

            NAudio.Wave.WaveFileReader wf = new NAudio.Wave.WaveFileReader(fileFullName);
            TimeSpan tp = wf.TotalTime;
            duration = tp.TotalSeconds.ToString();
            return true;
        }
コード例 #38
0
        private void jollyPicBox_Click_1(object sender, EventArgs e)
        {
            string file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\TeacherWAV\" + lvlStr.ToLower() + ".wav";

            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
コード例 #39
0
        public Soundsystem()
        {
            NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(
                new NAudio.Wave.Mp3FileReader("sounds/ambience-wind1.mp3"));

            ambience = new NAudio.Wave.BlockAlignReductionStream(pcm);

            pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(
                new NAudio.Wave.Mp3FileReader("music/zombi-drone.mp3"));

            drone = new NAudio.Wave.BlockAlignReductionStream(pcm);

            fire1 = new NAudio.Wave.WaveFileReader("sounds/gun-fire1.wav");
            fire2 = new NAudio.Wave.WaveFileReader("sounds/gun-fire2.wav");
            empty = new NAudio.Wave.WaveFileReader("sounds/gun-empty.wav");
            load = new NAudio.Wave.WaveFileReader("sounds/gun-load.wav");

            hitflesh1 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh1.wav");
            hitflesh2 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh2.wav");
            hitflesh3 = new NAudio.Wave.WaveFileReader("sounds/hit-flesh3.wav");
            hitmetal1 = new NAudio.Wave.WaveFileReader("sounds/hit-metal1.wav");
            hitmetal2 = new NAudio.Wave.WaveFileReader("sounds/hit-metal2.wav");
            hitmetal3 = new NAudio.Wave.WaveFileReader("sounds/hit-metal3.wav");
            hitrock = new NAudio.Wave.WaveFileReader("sounds/hit-rock1.wav");
            hitglass = new NAudio.Wave.WaveFileReader("sounds/hit-glass1.wav");

            walk1 = new NAudio.Wave.WaveFileReader("sounds/walk1.wav");
            walk2 = new NAudio.Wave.WaveFileReader("sounds/walk2.wav");
            walk3 = new NAudio.Wave.WaveFileReader("sounds/walk3.wav");
            walk4 = new NAudio.Wave.WaveFileReader("sounds/walk4.wav");
            walk5 = new NAudio.Wave.WaveFileReader("sounds/walk5.wav");
            walk6 = new NAudio.Wave.WaveFileReader("sounds/walk6.wav");
            walk7 = new NAudio.Wave.WaveFileReader("sounds/walk7.wav");
            walk8 = new NAudio.Wave.WaveFileReader("sounds/walk8.wav");

            zombi1 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan1.wav");
            zombi2 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan2.wav");
            zombi3 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan3.wav");
            zombi4 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan4.wav");
            zombi5 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan5.wav");
            zombi6 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan6.wav");
            zombi7 = new NAudio.Wave.WaveFileReader("sounds/zombi-moan7.wav");

            fire1_channel = new NAudio.Wave.WaveChannel32(fire1);
            fire1_channel.Volume = 0.0f;
            fire2_channel = new NAudio.Wave.WaveChannel32(fire2);
            fire2_channel.Volume = 0.0f;
            load_channel = new NAudio.Wave.WaveChannel32(load);
            load_channel.Volume = 0.0f;
            empty_channel = new NAudio.Wave.WaveChannel32(empty);
            empty_channel.Volume = 0.0f;

            hitglass_channel = new NAudio.Wave.WaveChannel32(hitglass);
            hitglass_channel.Volume = 0.0f;
            hitflesh1_channel = new NAudio.Wave.WaveChannel32(hitflesh1);
            hitflesh1_channel.Volume = 0.0f;
            hitflesh2_channel = new NAudio.Wave.WaveChannel32(hitflesh2);
            hitflesh2_channel.Volume = 0.0f;
            hitflesh3_channel = new NAudio.Wave.WaveChannel32(hitflesh3);
            hitflesh3_channel.Volume = 0.0f;
            hitrock_channel = new NAudio.Wave.WaveChannel32(hitrock);
            hitrock_channel.Volume = 0.0f;
            hitmetal1_channel = new NAudio.Wave.WaveChannel32(hitmetal1);
            hitmetal1_channel.Volume = 0.0f;
            hitmetal2_channel = new NAudio.Wave.WaveChannel32(hitmetal2);
            hitmetal2_channel.Volume = 0.0f;
            hitmetal3_channel = new NAudio.Wave.WaveChannel32(hitmetal3);
            hitmetal3_channel.Volume = 0.0f;

            walk1_channel = new NAudio.Wave.WaveChannel32(walk1);
            walk1_channel.Volume = 0.0f;
            walk2_channel = new NAudio.Wave.WaveChannel32(walk2);
            walk2_channel.Volume = 0.0f;
            walk3_channel = new NAudio.Wave.WaveChannel32(walk3);
            walk3_channel.Volume = 0.0f;
            walk4_channel = new NAudio.Wave.WaveChannel32(walk4);
            walk4_channel.Volume = 0.0f;
            walk5_channel = new NAudio.Wave.WaveChannel32(walk5);
            walk5_channel.Volume = 0.0f;
            walk6_channel = new NAudio.Wave.WaveChannel32(walk6);
            walk6_channel.Volume = 0.0f;
            walk7_channel = new NAudio.Wave.WaveChannel32(walk7);
            walk7_channel.Volume = 0.0f;
            walk8_channel = new NAudio.Wave.WaveChannel32(walk8);
            walk8_channel.Volume = 0.0f;

            zombi1_channel = new NAudio.Wave.WaveChannel32(zombi1);
            zombi1_channel.Volume = 0.0f;
            zombi2_channel = new NAudio.Wave.WaveChannel32(zombi2);
            zombi2_channel.Volume = 0.0f;

            zombi3_channel = new NAudio.Wave.WaveChannel32(zombi3);
            zombi3_channel.Volume = 0.0f;

            zombi4_channel = new NAudio.Wave.WaveChannel32(zombi4);
            zombi4_channel.Volume = 0.0f;

            zombi5_channel = new NAudio.Wave.WaveChannel32(zombi5);
            zombi5_channel.Volume = 0.0f;

            zombi6_channel = new NAudio.Wave.WaveChannel32(zombi6);
            zombi6_channel.Volume = 0.0f;

            zombi7_channel = new NAudio.Wave.WaveChannel32(zombi7);
            zombi7_channel.Volume = 0.0f;

            mikseri = new NAudio.Wave.WaveMixerStream32();

            ambience_channel = new NAudio.Wave.WaveChannel32(ambience);
            ambience_channel.Volume = 0.2f;

            drone_channel = new NAudio.Wave.WaveChannel32(drone);
            drone_channel.Volume = 0.5f;

            mikseri.AddInputStream(fire1_channel);
            mikseri.AddInputStream(fire2_channel);
            mikseri.AddInputStream(empty_channel);
            mikseri.AddInputStream(load_channel);

            mikseri.AddInputStream(hitflesh1_channel);
            mikseri.AddInputStream(hitflesh2_channel);
            mikseri.AddInputStream(hitflesh3_channel);
            mikseri.AddInputStream(hitmetal1_channel);
            mikseri.AddInputStream(hitmetal2_channel);
            mikseri.AddInputStream(hitmetal3_channel);
            mikseri.AddInputStream(hitrock_channel);
            mikseri.AddInputStream(hitglass_channel);

            mikseri.AddInputStream(walk1_channel);
            mikseri.AddInputStream(walk2_channel);
            mikseri.AddInputStream(walk3_channel);
            mikseri.AddInputStream(walk4_channel);
            mikseri.AddInputStream(walk5_channel);
            mikseri.AddInputStream(walk6_channel);
            mikseri.AddInputStream(walk7_channel);
            mikseri.AddInputStream(walk8_channel);

            mikseri.AddInputStream(zombi1_channel);
            mikseri.AddInputStream(zombi2_channel);
            mikseri.AddInputStream(zombi3_channel);
            mikseri.AddInputStream(zombi4_channel);
            mikseri.AddInputStream(zombi5_channel);
            mikseri.AddInputStream(zombi6_channel);
            mikseri.AddInputStream(zombi7_channel);

            mikseri.AddInputStream(ambience_channel);
            mikseri.AddInputStream(drone_channel);

            mikseri.AutoStop = false;

            output = new NAudio.Wave.DirectSoundOut();
            output.Init(mikseri);

            soundson = true;
            output.Play();
        }
コード例 #40
0
 //Dispose the wave
 private void DisposeWave()
 {
     if (output != null)
     {
         //If it's still playing, stop
         if (output.PlaybackState == NAudio.Wave.PlaybackState.Playing)
         {
             output.Stop();
         }
         output.Dispose();
         output = null;
     }
     if (wave != null)
     {
         wave.Dispose();
         wave = null;
     }
 }
コード例 #41
0
ファイル: UI_ConfigSC.cs プロジェクト: 9001/Loopstream
 void playFX(LSDevice dev)
 {
     if (unFxTimer == null)
     {
         unFxTimer = new Timer();
         unFxTimer.Interval = 3000;
         unFxTimer.Tick += delegate(object oa, EventArgs ob)
         {
             unFX();
         };
     }
     try
     {
         if (disregardEvents) return;
         unFX();
         fx_stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Loopstream.res.sc.wav");
         //fx_mp3 = new NAudio.Wave.Mp3FileReader(fx_stream);
         fx_wav = new NAudio.Wave.WaveFileReader(fx_stream);
         fx_out = new NAudio.Wave.WasapiOut(dev.mm, NAudio.CoreAudioApi.AudioClientShareMode.Shared, false, 100);
         fx_out.Init(fx_wav);
         fx_out.Play();
         unFxTimer.Start();
     }
     catch { }
 }
コード例 #42
0
ファイル: Form1.cs プロジェクト: FlipSchaefer/EpicBoard
        private void sound1_Click(object sender, EventArgs e)
        {

            int deviceNumberIn = inputComboBox.SelectedIndex;
            int deviceNumberOut = outputComboBox.SelectedIndex;

            if (waveReader == null)
            {
                dialog = new OpenFileDialog();
                dialog.InitialDirectory = soundFolderTextBox.Text;
                dialog.Filter = "Audio Files (.wav)|*.wav";

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    sound1.Text = dialog.FileName;
                    //sourceStream = new NAudio.Wave.WaveIn();
                    sourceOutStream = new NAudio.Wave.WaveOut();
                    sourceOutStream.DeviceNumber = deviceNumberOut;

                       //sourceStream.DeviceNumber = deviceNumber;
                       //sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);

                       //NAudio.Wave.WaveInProvider waveIn = new NAudio.Wave.WaveInProvider(sourceStream);

                       //output.Init(waveIn);

                       //sourceStream.StartRecording();
                       //output.Play();

                  

                    waveReader = new NAudio.Wave.WaveFileReader(dialog.FileName);
                    sourceOutStream.Init(new NAudio.Wave.WaveChannel32(waveReader));
                    //output.Init(new NAudio.Wave.WaveChannel32(waveReader));
                    sourceOutStream.Play();
                    //output.Play();
                }

            }
            else
            {
                //Wenn schon vorhanden
                //Play sound
                waveReader = new NAudio.Wave.WaveFileReader(dialog.FileName);
                output.Init(new NAudio.Wave.WaveChannel32(waveReader));
                sourceOutStream.Init(new NAudio.Wave.WaveChannel32(waveReader));
                sourceOutStream.Play();
                //output.Play();
            }



        }
コード例 #43
0
        private void jollyPicBox_Click(object sender, EventArgs e)
        {
            string file = "Class" + LoginForm.classSec + "_kidAudio/" + lvlStr.ToLower() + ".wav";

            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
コード例 #44
0
        private void playSound(String res)
        {
            string file;
            if (res.Equals("WON"))
            {
                file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\Mario Coin.wav";
            }
            else
            {
                file = @"C:\Pres_Proto\V2\MetroFrameworkDLLExample\lose.wav";
            }

            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(file);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
コード例 #45
0
            private void OpenWaveFile(out int Sample_Freq, out double[] SignalETC)
            {
                NAudio.Wave.WaveFileReader WP = new NAudio.Wave.WaveFileReader(Signal_Status.Text);

                int BytesPerSample = WP.WaveFormat.Channels * WP.WaveFormat.BitsPerSample / 8;
                int BytesPerChannel = WP.WaveFormat.BitsPerSample / 8;
                byte[] signalbuffer = new byte[BytesPerSample];
                int ChannelCt = WP.WaveFormat.Channels;
                Sample_Freq = WP.WaveFormat.SampleRate;
                double[] SignalInt = new double[WP.SampleCount];

                if (WP.WaveFormat.BitsPerSample == 8)
                {
                    System.Windows.Forms.MessageBox.Show("Selected File is an 8-Bit audio file. This program requires a minimum bit-depth of 16.");
                    SignalETC = new double[SignalInt.Length];
                    return;
                }
                byte[] temp = new byte[4];
                int c = (int)DryChannel.Value - 1;
                //double Max;

                //switch (WP.WaveFormat.BitsPerSample)
                //{
                //    case 32:
                //        Max = Int32.MaxValue;
                //        break;
                //    case 24:
                //        Max = BitConverter.ToInt32(new byte[] { 0, byte.MaxValue, byte.MaxValue, byte.MaxValue }, 0);
                //        break;
                //    case 16:
                //        Max = Int16.MaxValue;
                //        break;
                //    case 8:
                //        Max = BitConverter.ToInt16(new byte[] { 0, byte.MaxValue }, 0);
                //        break;
                //    default:
                //        throw new Exception("Invalid bit depth variable... Where did you get this audio file again?");
                //}

                for (int i = 0; i < WP.SampleCount; i++)
                {
                    WP.Read(signalbuffer, 0, BytesPerSample);

                    if (WP.WaveFormat.BitsPerSample == 32)
                    {
                        SignalInt[i] = BitConverter.ToInt32(signalbuffer, c * 4);
                    }
                    else if (WP.WaveFormat.BitsPerSample == 24)
                    {
                        temp[1] = signalbuffer[c * BytesPerChannel];
                        temp[2] = signalbuffer[c * BytesPerChannel + 1];
                        temp[3] = signalbuffer[c * BytesPerChannel + 2];
                        SignalInt[i] = BitConverter.ToInt32(temp, 0);
                    }
                    else if (WP.WaveFormat.BitsPerSample == 16)
                    {
                        temp[2] = signalbuffer[c * BytesPerChannel];
                        temp[3] = signalbuffer[c * BytesPerChannel + 1];
                        SignalInt[i] = BitConverter.ToInt32(temp, 0);
                    }
                }

                SignalETC = new double[SignalInt.Length];

                double Max = double.NegativeInfinity;
                for(int i = 0; i < SignalInt.Length; i++)
                {
                    Max = Math.Max(Max, Math.Abs(SignalInt[i]));
                }

                for(int i = 0; i < SignalInt.Length; i++)
                {
                    SignalETC[i] = SignalInt[i] / Max;
                }
                SignalETC = SignalInt;

            }
コード例 #46
0
ファイル: Program.cs プロジェクト: TomasMarkevicius/KokoroBot
        private async static void PlaySoundWav(MessageEventArgs e)
        {
            if (e.Message.Text.Length > "-play ".Length && voiceclient != null)
            {
                string file = e.Message.Text.Substring("-play ".Length);
                Console.WriteLine("Trying to play: " + file);
                try {
                    var ws = new NAudio.Wave.WaveFileReader(file);
                    byte[] buf;
                    if (ws.WaveFormat.Channels > 1)
                    {
                        var tomono = new NAudio.Wave.StereoToMonoProvider16(ws);
                        tomono.RightVolume = 0.5f;
                        tomono.LeftVolume = 0.5f;
                        buf = new byte[ws.Length];
                        while (ws.HasData(ws.WaveFormat.AverageBytesPerSecond))
                        {
                            tomono.Read(buf, 0, ws.WaveFormat.AverageBytesPerSecond);
                            voiceclient.SendVoicePCM(buf, buf.Length);
                        }
                    }
                    else
                    {
                        buf = new byte[ws.Length];
                        ws.Read(buf, 0, buf.Length);
                        voiceclient.SendVoicePCM(buf, buf.Length);
                    }
                    ws.Close();
                }
                catch(Exception)
                {
                    Console.WriteLine("File not found or incompatible.");
                }

            }
        }
コード例 #47
0
 private void Play_TTS_file(string filename)
 {
     Console.WriteLine("In Play_TTS_file start");
     NAudio.Wave.WaveFileReader audio = new NAudio.Wave.WaveFileReader(filename);
     NAudio.Wave.IWavePlayer player = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback());
     player.Init(audio);
     player.Play();
     while (true)
     {
         if (player.PlaybackState == NAudio.Wave.PlaybackState.Stopped)
         {
             player.Dispose();
             //MessageBox.Show("disposed");
             audio.Close();
             audio.Dispose();
             break;
         }
     };
     Console.WriteLine("After Play_TTS_File while loop");
 }
コード例 #48
0
        //Plays/Repeats the audio of the letter
        private void repeatBtn_Click(object sender, EventArgs e)
        {
            String filename = "Class" + LoginForm.classSec + "_kidAudio/" + letters[curPos] + ".wav";
            DisposeWave();

            wave = new NAudio.Wave.WaveFileReader(filename);
            output = new NAudio.Wave.DirectSoundOut();
            output.Init(new NAudio.Wave.WaveChannel32(wave));
            output.Play();
        }
コード例 #49
0
 private void OpenSignal_Click(object sender, System.EventArgs e)
 {
     GetWave.Filter = " Wave Audio (*.wav) |*.wav";
     if (GetWave.ShowDialog() == DialogResult.OK)
     {
         Signal_Status.Text = GetWave.FileName;
         RenderBtn.Enabled = true;
         NAudio.Wave.WaveFileReader WR = new NAudio.Wave.WaveFileReader(Signal_Status.Text);
         DryChannel.Minimum = 1;
         DryChannel.Maximum = WR.WaveFormat.Channels;
     }
 }
コード例 #50
0
            private void OpenWaveFile(out int Sample_Freq, out double[] SignalETC)
            {
                NAudio.Wave.WaveFileReader WP = new NAudio.Wave.WaveFileReader(Signal_Status.Text);

                int BytesPerSample = WP.WaveFormat.Channels * WP.WaveFormat.BitsPerSample / 8;
                int BytesPerChannel = WP.WaveFormat.BitsPerSample / 8;
                byte[] signalbuffer = new byte[BytesPerSample];
                int ChannelCt = WP.WaveFormat.Channels;
                Sample_Freq = WP.WaveFormat.SampleRate;
                double[] SignalInt = new double[WP.SampleCount]; //[Sample]

                if (WP.WaveFormat.BitsPerSample == 8)
                {
                    System.Windows.Forms.MessageBox.Show("Selected File is an 8-Bit audio file. This program requires a minimum bit-depth of 16.");
                    SignalETC = new double[SignalInt.Length];
                    return;
                }
                byte[] temp = new byte[4];
                int c = (int)DryChannel.Value - 1;
                double Max;

                switch (WP.WaveFormat.BitsPerSample)
                {
                    case 32:
                        Max = Int32.MaxValue;
                        break;
                    case 24:
                        Max = BitConverter.ToInt32(new byte[] { 0, byte.MaxValue, byte.MaxValue, byte.MaxValue }, 0);
                        break;
                    case 16:
                        Max = Int16.MaxValue;
                        break;
                    case 8:
                        Max = BitConverter.ToInt16(new byte[] {0, byte.MaxValue}, 0);
                        break;
                    default:
                        throw new Exception("Invalid bit depth variable... Where did you get this audio file again?");
                }

                for (int i = 0; i < WP.SampleCount; i++)//Have we chosen the right property to get the number of bytes in the file?
                {
                    WP.Read(signalbuffer, 0, BytesPerSample);

                    if (WP.WaveFormat.BitsPerSample == 32)
                    {
                        SignalInt[i] = BitConverter.ToInt32(signalbuffer, c * 4);
                    }
                    else if (WP.WaveFormat.BitsPerSample == 24)
                    {
                        temp[1] = signalbuffer[c * BytesPerChannel];
                        temp[2] = signalbuffer[c * BytesPerChannel + 1];
                        temp[3] = signalbuffer[c * BytesPerChannel + 2];
                        SignalInt[i] = BitConverter.ToInt32(temp, 0);
                    }
                    else if (WP.WaveFormat.BitsPerSample == 16)
                    {
                        temp[2] = signalbuffer[c * BytesPerChannel];
                        temp[3] = signalbuffer[c * BytesPerChannel + 1];
                        SignalInt[i] = BitConverter.ToInt32(temp, 0);
                    }
                }

                SignalETC = SignalInt;
            }