Example #1
0
        public HttpResponseMessage MakeCoolTrack([FromForm] KaraokeElems value)
        {
            string name = value.TrackName;
            // Getting Image
            var image = value.VoiceFile;

            try
            {
                var voiceFile = "Assets/Yours/" + image.FileName.Substring(0, image.FileName.Length - 4) +
                                "-your-voice.mp3";
                var instFile = "Assets/Nirvana Smells Like Teen Spirit Inst.mp3";

                var trackFile = "Assets/Yours/" + image.FileName.Substring(0, image.FileName.Length - 4) +
                                "-your-track.mp3";

                // Saving Image on Server
                if (image.Length > 0)
                {
                    using (var fileStream = new FileStream(voiceFile, FileMode.Create))
                    {
                        image.CopyTo(fileStream);
                    }
                }

                var voiceWaveSource = CodecFactory.Instance.GetCodec(voiceFile);
                var instWaveSource  = CodecFactory.Instance.GetCodec(instFile);

                using (var cAurio = new AudioControler())
                {
                    VolumeSource vol1, vol2;
                    var          yourTrack = cAurio.MixAudioAndVoice(instWaveSource, out vol1, voiceWaveSource, out vol2);

                    vol1.Volume = 0.5f;
                    vol2.Volume = 0.5f;

                    using (var encoder = MediaFoundationEncoder.CreateMP3Encoder(yourTrack.WaveFormat, trackFile))
                    {
                        byte[] buffer = new byte[yourTrack.WaveFormat.BytesPerSecond];
                        int    read;
                        while ((read = yourTrack.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            encoder.Write(buffer, 0, read);

                            //Console.CursorLeft = 0;
                            //Console.Write("{0:P}/{1:P}", (double) yourTrack.Position / yourTrack.Length, 1);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
 public void Post([FromForm] KaraokeElems value)
 {
 }