public string ConvertToWav(string fileName)
        {
            FileInfo outputFormat = new FileInfo
            {
                FileType = FileType.Wav,
                Channels = 1,
                SampleSizeInBits = 8,
                SamplingRate = _samplingRate,
                EncodingType = EncodingType.UnsignedInteger
            };

            var fileNameExt = Path.GetExtension(fileName);
            ConvertOptions convertOptions = new ConvertOptions
            {
                InputFileInfo = new FileInfo
                {
                    FileType = Sox.GetFileTypeFromExtension(fileNameExt)
                },
                OutputFileInfo = outputFormat
            };
            using (Stream input = File.OpenRead(fileName))
            {
                string resultFileName = Path.GetTempFileName();
                _sox.Convert(input, convertOptions).WriteToFile(resultFileName);
                return resultFileName;
            }
        }
        public Stream Convert(string fileName)
        {
            FileInfo rawFileFormat = new FileInfo
            {
                FileType = FileType.RawUnsignedInteger8,
                Channels = 1,
                SampleSizeInBits = 8,
                SamplingRate = _samplingRate,
                EncodingType = EncodingType.UnsignedInteger
            };

            var fileNameExt = Path.GetExtension(fileName);
            ConvertOptions convertOptions = new ConvertOptions
            {
                InputFileInfo = new FileInfo
                {
                    FileType = Sox.GetFileTypeFromExtension(fileNameExt)
                },
                OutputFileInfo = rawFileFormat
            };
            using (Stream input = File.OpenRead(fileName))
            {
                return _sox.Convert(input, convertOptions);
            }
        }
        public string ConvertToWav(string sourceFileName, string destinationFileName, bool highQuality = false)
        {
            _log.Debug(string.Format("Atempting to convert '{0}' to '{1}'", sourceFileName, destinationFileName));
            FileInfo outputFormat = new FileInfo
            {
                FileType = FileType.Wav,
                Channels = 1,
                SampleSizeInBits = 8,
                SamplingRate = highQuality ? SAMPLING_RATE * 2 : SAMPLING_RATE,
                EncodingType = EncodingType.UnsignedInteger
            };

            var fileNameExt = Path.GetExtension(sourceFileName);
            ConvertOptions convertOptions = new ConvertOptions
            {
                InputFileInfo = new FileInfo
                {
                    FileType = Sox.GetFileTypeFromExtension(fileNameExt)
                },
                OutputFileInfo = outputFormat
            };
            using (Stream input = File.OpenRead(sourceFileName))
            {
                string resultFileName = string.IsNullOrEmpty(destinationFileName) ? Path.GetTempFileName() : destinationFileName;
                using (var tempConvertedFileStream = _sox.Convert(input, convertOptions))
                {
                    tempConvertedFileStream.WriteToFile(resultFileName);
                };
                return resultFileName;
            }
        }
Beispiel #4
0
        public Stream Convert(Stream input, ConvertOptions options)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            string outputExtension = GetFileExtension(options.OutputFileInfo.FileType);
            string inputExtensions = GetFileExtension(options.InputFileInfo.FileType);

            var inputTempFileName = Path.Combine(TempDir, Guid.NewGuid() + inputExtensions);
            input.WriteToFile(inputTempFileName);
            var outputTempFileName = Path.Combine(TempDir, Guid.NewGuid() + outputExtension);
            var cmdLineArgs = BuildConvertCommandLineArgs(inputTempFileName, outputTempFileName, options);
            var soxExeLocation = Path.GetFullPath(Path.Combine(SoxDirectory, "sox.exe"));
            RunSox(soxExeLocation, cmdLineArgs);
            File.Delete(inputTempFileName);
            return new DeleteFileStream(outputTempFileName);
        }
Beispiel #5
0
        public Stream Convert(Stream input, ConvertOptions options)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            string outputExtension = GetFileExtension(options.OutputFileInfo.FileType);
            string inputExtensions = GetFileExtension(options.InputFileInfo.FileType);

            var inputTempFileName = Path.Combine(TempDir, Guid.NewGuid() + inputExtensions);

            input.WriteToFile(inputTempFileName);
            var outputTempFileName = Path.Combine(TempDir, Guid.NewGuid() + outputExtension);
            var cmdLineArgs        = BuildConvertCommandLineArgs(inputTempFileName, outputTempFileName, options);
            var soxExeLocation     = Path.GetFullPath(Path.Combine(SoxDirectory, "sox.exe"));

            RunSox(soxExeLocation, cmdLineArgs);
            File.Delete(inputTempFileName);
            return(new DeleteFileStream(outputTempFileName));
        }
Beispiel #6
0
        private string BuildConvertCommandLineArgs(string inputFileName, string outputFileName, ConvertOptions options)
        {
            StringBuilder result = new StringBuilder();

            result.Append(BuildCommandLineArgs(options.InputFileInfo));
            result.Append(" " + inputFileName);
            result.Append(BuildCommandLineArgs(options.OutputFileInfo));
            result.Append(" " + outputFileName);
            return(result.ToString());
        }
Beispiel #7
0
 private string BuildConvertCommandLineArgs(string inputFileName, string outputFileName, ConvertOptions options)
 {
     StringBuilder result = new StringBuilder();
     result.Append(BuildCommandLineArgs(options.InputFileInfo));
     result.Append(" " + inputFileName);
     result.Append(BuildCommandLineArgs(options.OutputFileInfo));
     result.Append(" " + outputFileName);
     return result.ToString();
 }