示例#1
0
        private void LoadWaveFile()
        {
            const string _urlPrefix = @"file://";

            try {
                SetEnablings(false);

                string sTmpFilename = Path.GetTempFileName();
                File.Delete(sTmpFilename);
                sTmpFilename = Path.ChangeExtension(sTmpFilename, "wav");

                _waveStream = GetWaveStream(txtSynthesizer.Text, txtMusicString.Text);
                using (var fileStream = new FileStream(sTmpFilename, FileMode.OpenOrCreate, FileAccess.Write)) {
                    _waveStream.CopyTo(fileStream);
                }

                _mediaPlayer.settings.autoStart = true;
                //	mediaPlayer.Visible	            = true;
                _mediaPlayer.URL = _urlPrefix + sTmpFilename;
                _mediaPlayer.Tag = sTmpFilename;                                // to aid in clean-up later
                _mediaPlayer.Ctlcontrols.play();
            }
            catch (SynthesizerParseErrorsException ex) {
                MessageBox.Show(ex.Message);
                SetEnablings(true);                             // Aborted, so enable interface
            }
            finally {
                Refresh();
            }
        }
示例#2
0
 public void Encode(WaveStream waveData, Stream outputStream)
 {
     using (LameMP3FileWriter mp3 = new LameMP3FileWriter(outputStream, waveData.WaveFormat, 128))
     {
         waveData.CopyTo(mp3);
     }
 }
示例#3
0
 public void Encode(WaveStream waveData, Stream output)
 {
     var wav = new WaveFileWriter(output, waveData.WaveFormat);
     {
         waveData.CopyTo(wav);
     }
 }
示例#4
0
 public MemoryStream ToMp3(WaveStream wavFile)
 {
     using (var retMs = new MemoryStream())
         using (var wtr = new LameMP3FileWriter(retMs, wavFile.WaveFormat, 128))
         {
             wavFile.CopyTo(wtr);
             return(retMs);
         }
 }
示例#5
0
        public static int Main(string[] args)
        {
            try
            {
                Stream sysin = new MemoryStream();
                Console.OpenStandardInput().CopyTo(sysin);

                Console.Error.WriteLine($"Copied STDIN, length {sysin.Length}");

                string id3Title     = Environment.GetEnvironmentVariable("FFM_ID3_TITLE");
                string id3Author    = Environment.GetEnvironmentVariable("FFM_ID3_AUTHOR");
                string mimeHint     = Environment.GetEnvironmentVariable("FFM_MIME");
                int?   limitSeconds = Environment.GetEnvironmentVariable("FFM_MAX_SECONDS") == null ?
                                      new int?() :
                                      Convert.ToInt32(Environment.GetEnvironmentVariable("FFM_MAX_SECONDS"));

                string typeString = InferInformationString(sysin, mimeHint);
                Console.Error.WriteLine($"TypeString is {typeString}");

                AudioFormat audioFormat = AudioFormatFromString(typeString);
                Console.Error.WriteLine($"AudioFormat is {audioFormat}");

                sysin.Position = 0;
                WaveStream readerStream = ReaderForAudioFormat(sysin, audioFormat, limitSeconds, out int seconds);
                Console.Error.WriteLine($"ReaderStream is {readerStream}");

                Stream sysout = Console.OpenStandardOutput();

                var fileWriter = new LameMP3FileWriter
                                 (
                    sysout,
                    readerStream.WaveFormat,
                    320,
                    new ID3TagData
                {
                    Title  = id3Title,
                    Artist = id3Author,
                }
                                 );

                Console.Error.WriteLine($"Setting Debug,Error,Message functions on fileWriter");

                fileWriter.SetDebugFunction(txt => Console.Error.WriteLine(txt));
                fileWriter.SetErrorFunction(txt => Console.Error.WriteLine(txt));
                fileWriter.SetMessageFunction(txt => Console.Error.WriteLine(txt));

                Console.Error.WriteLine($"Streaming operations now!");

                readerStream.CopyTo(fileWriter);
                fileWriter.Flush();
                fileWriter.Close();

                sysout.Close();

                return(seconds);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Console.Error.Flush();
                return(-1);
            }
        }