示例#1
0
        /// <summary>
        /// Преобразует поток с wav файлом в mp3
        /// </summary>
        /// <param name="wavFile"></param>
        public static void WavToMP3(string wavPath, string Mp3path)
        {
            using (Stream source = new FileStream(wavPath, FileMode.Open))
                using (Stream Mp3file = new FileStream(Mp3path, FileMode.Create))
                    using (NAudio.Wave.WaveFileReader rdr = new NAudio.Wave.WaveFileReader(source))
                    {
                        WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(rdr.WaveFormat.SampleRate, rdr.WaveFormat.BitsPerSample, rdr.WaveFormat.Channels);

                        // convert to MP3 at 96kbit/sec...
                        Yeti.Lame.BE_CONFIG conf = new Yeti.Lame.BE_CONFIG(fmt, 96);

                        // Allocate a 1-second buffer
                        int    blen   = rdr.WaveFormat.AverageBytesPerSecond;
                        byte[] buffer = new byte[blen];

                        Yeti.MMedia.Mp3.Mp3Writer mp3 = new Yeti.MMedia.Mp3.Mp3Writer(Mp3file, fmt, conf);

                        int readCount;
                        while ((readCount = rdr.Read(buffer, 0, blen)) > 0)
                        {
                            mp3.Write(buffer, 0, readCount);
                        }

                        Mp3file.Flush();
                        mp3.Close();
                    }
        }
示例#2
0
        public static byte[] WavToMP3(byte[] wavFile)
        {
            using (MemoryStream source = new MemoryStream(wavFile))
                using (WaveFileReader rdr = new WaveFileReader(source))
                {
                    WaveLib.WaveFormat fmt = new WaveLib.WaveFormat(rdr.WaveFormat.SampleRate, rdr.WaveFormat.BitsPerSample, rdr.WaveFormat.Channels);

                    // convert to MP3 at 96kbit/sec...
                    Yeti.Lame.BE_CONFIG conf = new Yeti.Lame.BE_CONFIG(fmt, 96);

                    // Allocate a 1-second buffer
                    int    blen   = rdr.WaveFormat.AverageBytesPerSecond;
                    byte[] buffer = new byte[blen];

                    // Do conversion
                    using (MemoryStream output = new MemoryStream())
                    {
                        Yeti.MMedia.Mp3.Mp3Writer mp3 = new Yeti.MMedia.Mp3.Mp3Writer(output, fmt, conf);

                        int readCount;
                        while ((readCount = rdr.Read(buffer, 0, blen)) > 0)
                        {
                            mp3.Write(buffer, 0, readCount);
                        }

                        mp3.Close();
                        return(output.ToArray());
                    }
                }
        }
示例#3
0
 protected override void OnStreamingStoppedSuspended(SoundStreamingStatus streamingStatus)
 {
     base.OnStreamingStoppedSuspended(streamingStatus);
     if (mp3Writer != null)
     {
         mp3Writer.Close();
         mp3Writer = null;
     }
 }
示例#4
0
        protected override void OnStreamingStartedResumed()
        {
            base.OnStreamingStartedResumed();

            WaveLib.WaveFormat waveFormat   = YetiWaveFormat;
            Mp3SoundFormat     outputFormat = (Mp3SoundFormat)OutputFormat;

            mp3Writer = new Yeti.MMedia.Mp3.Mp3Writer(Output,
                                                      waveFormat, new Yeti.Lame.BE_CONFIG(waveFormat, outputFormat.BitRate,
                                                                                          Yeti.Lame.LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY), false);
        }
示例#5
0
        private static void wavToMp3(Stream streamToWav, Stream outputStream, uint desiredOutputBitRate)
        {
            var mp3Config = new Yeti.MMedia.Mp3.Mp3WriterConfig((streamToWav as WaveLib.WaveStream).Format, desiredOutputBitRate);

            var mp3Writer = new Yeti.MMedia.Mp3.Mp3Writer(outputStream, mp3Config);

            byte[] buff  = new byte[mp3Writer.OptimalBufferSize];
            int    read  = 0;
            long   total = streamToWav.Length;

            streamToWav.Position = 0;
            while ((read = streamToWav.Read(buff, 0, buff.Length)) > 0)
            {
                mp3Writer.Write(buff, 0, read);
            }

            mp3Writer.Close();
            streamToWav.Close();
        }
示例#6
0
        private static void wavToMp3(Stream streamToWav, Stream outputStream, uint desiredOutputBitRate)
        {
            var mp3Config = new Yeti.MMedia.Mp3.Mp3WriterConfig((streamToWav as WaveLib.WaveStream).Format, desiredOutputBitRate);

            var mp3Writer = new Yeti.MMedia.Mp3.Mp3Writer(outputStream, mp3Config);
            byte[] buff = new byte[mp3Writer.OptimalBufferSize];
            int read = 0;
            long total = streamToWav.Length;
            streamToWav.Position = 0;
            while ((read = streamToWav.Read(buff, 0, buff.Length)) > 0)
                mp3Writer.Write(buff, 0, read);

            mp3Writer.Close();
            streamToWav.Close();
        }
 private static byte[] transcode(byte[] buffer)
 {
     MemoryStream outputStream = new MemoryStream();
     try
     {
         var writer = new Yeti.MMedia.Mp3.Mp3Writer(outputStream, inputFormat, mp3Format);
         writer.Write(buffer);
         writer.Flush();
     }
     catch (Exception e)
     {
         Logger.Log("Exception in MP3 encoding of Microphone input: " + e.Message);
     }
     return outputStream.ToArray();
 }