Exemple #1
0
        /// <summary>
        /// Processes the wave file into the destination output format, deletes the temporary files and returns the result as a byte array
        /// </summary>
        /// <param name="format"></param>
        /// <param name="tempfile"></param>
        /// <returns></returns>
        private byte[] ConvertToAudioFormat(int format, string tempfile)
        {
            try
            {
                //output file to the correct format
                OutputEncodingProcessor oep = new OutputEncodingProcessor();
                string outputFile = "", fileName = Guid.NewGuid().ToString() + ".wav";
                switch (format)
                {
                case 1:
                    fileName   = Guid.NewGuid().ToString() + ".mp3";
                    outputFile = Path.Combine(Path.GetTempPath(), fileName);
                    File.Create(outputFile).Close();
                    oep.WaveToMP3(tempfile, outputFile, 32);
                    break;

                case 2:
                    //tempfile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".wav");
                    outputFile = tempfile;
                    tempfile   = "do not delete";
                    break;

                case 4:
                    fileName   = Guid.NewGuid().ToString() + ".wma";
                    outputFile = Path.Combine(Path.GetTempPath(), fileName);
                    File.Create(outputFile).Close();
                    oep.WaveToWMA(tempfile, outputFile, 44100);
                    break;

                case 8:
                    fileName   = Guid.NewGuid().ToString() + ".aac";
                    outputFile = Path.Combine(Path.GetTempPath(), fileName);
                    File.Create(outputFile).Close();
                    if (oep.IsWinVistaOrHigher())
                    {
                        oep.WaveToAAC(tempfile, outputFile, 44100);
                    }
                    else
                    {
                        File.Copy(tempfile, outputFile, true);
                    }
                    break;
                }
                byte[] result = File.ReadAllBytes(outputFile);
                if (File.Exists(tempfile))
                {
                    File.Delete(tempfile);
                }
                if (File.Exists(outputFile))
                {
                    File.Delete(outputFile);
                }
                //start put result on WEBSERVER2 file system
                string toSend = @"\\WEBSERVER2\Temp\" + fileName;
                File.WriteAllBytes(toSend, result);
                byte[] pathResult = Encoding.UTF8.GetBytes(toSend);
                //stop
                Console.WriteLine("Job Done.");
                return(pathResult);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
 /// <summary>
 /// Processes the wave file into the destination output format, deletes the temporary files and returns the result as a byte array
 /// </summary>
 /// <param name="format"></param>
 /// <param name="tempfile"></param>
 /// <returns></returns>
 private byte[] ConvertToAudioFormat(int format, string tempfile)
 {
     try
     {
         //output file to the correct format
         OutputEncodingProcessor oep = new OutputEncodingProcessor();
         string outputFile = "",fileName=Guid.NewGuid().ToString() + ".wav";
         switch (format)
         {
             case 1:
                 fileName = Guid.NewGuid().ToString() + ".mp3";
                 outputFile = Path.Combine(Path.GetTempPath(), fileName);
                 File.Create(outputFile).Close();
                 oep.WaveToMP3(tempfile, outputFile);
                 break;
             case 2:
                 //tempfile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".wav");
                 outputFile = tempfile;
                 tempfile = "do not delete";
                 break;
             case 4:
                 fileName = Guid.NewGuid().ToString() + ".wma";
                 outputFile = Path.Combine(Path.GetTempPath(), fileName);
                 File.Create(outputFile).Close();
                 oep.WaveToWMA(tempfile, outputFile, 44100);
                 break;
             case 8:
                 fileName = Guid.NewGuid().ToString() + ".aac";
                 outputFile = Path.Combine(Path.GetTempPath(), fileName);
                 File.Create(outputFile).Close();
                 if (oep.IsWinVistaOrHigher())
                     oep.WaveToAAC(tempfile, outputFile, 44100);
                 else
                     File.Copy(tempfile, outputFile, true);
                 break;
         }
         byte[] result = File.ReadAllBytes(outputFile);
         if (File.Exists(tempfile))
             File.Delete(tempfile);
         if (File.Exists(outputFile))
             File.Delete(outputFile);
         //start put result on WEBSERVER2 file system
         string toSend = @"\\WEBSERVERPATH\Temp\"+fileName;
         //string toSend = @"C:\RoboBrailleWebApi\Temp" + fileName;
         File.WriteAllBytes(toSend, result);
         byte[] pathResult = Encoding.UTF8.GetBytes(toSend);
         //stop
         Console.WriteLine("Job Done.");
         return pathResult;
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return null;
     }
 }