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 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); } }
public void ConvertWavToRaw() { Sox sox = new Sox { SoxDirectory = Path.Combine(TestHelper.GetSolutionDirectory(), @"libs\sox-14.3.2\") }; ConvertOptions options = new ConvertOptions { InputFileInfo = new FileInfo { FileType = FileType.Wav, }, OutputFileInfo = new FileInfo { FileType = FileType.RawUnsignedInteger8, Channels = 1, SampleSizeInBits = 8, SamplingRate = 8000, EncodingType = EncodingType.UnsignedInteger } }; int preRunTempDirFileCount = Directory.GetFiles(sox.TempDir).Length; using (Stream input = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh.wav")) using (Stream expected = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh-wav.u8")) using (Stream output = sox.Convert(input, options)) { StreamTestHelper.AssertAreEqual(expected, output, 2); } Assert.AreEqual(preRunTempDirFileCount, Directory.GetFiles(sox.TempDir).Length); }
private void btnConvert_Click(object sender, EventArgs e) { string soxPath = tbSoxPath.Text; string inputFile = tbInput.Text; string outputFile = tbOutput.Text; if (string.IsNullOrEmpty(soxPath)) { MessageBox.Show("Please specify path to Sox executable file"); return; } if (string.IsNullOrEmpty(inputFile)) { MessageBox.Show("Please specify path to "); return; } if (string.IsNullOrEmpty(outputFile)) { MessageBox.Show("Please specify path to "); return; } try { SoxAudioFileType OutputType = (SoxAudioFileType)(AudioFileIndex); Sox.Convert(soxPath, inputFile, outputFile, OutputType); MessageBox.Show("Complete!"); } catch (SoxException ex) { MessageBox.Show(String.Format("{0}: {1}", ex.Code, ex.Message)); } }
public void ConvertWavToMp3() { Sox sox = new Sox { SoxDirectory = Path.Combine(TestHelper.GetSolutionDirectory(), @"libs\sox-14.3.2\") }; ConvertOptions options = new ConvertOptions { InputFileInfo = new FileInfo { FileType = FileType.Mp3, }, OutputFileInfo = new FileInfo { FileType = FileType.RawUnsignedInteger8, Channels = 1, SampleSizeInBits = 8, SamplingRate = 8000, EncodingType = EncodingType.UnsignedInteger } }; int preRunTempDirFileCount = Directory.GetFiles(sox.TempDir).Length; using (Stream input = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh.mp3")) using (Stream expected = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh-mp3.u8")) using (Stream output = sox.Convert(input, options)) { StreamTestHelper.AssertAreEqual(expected, output, 2); } Assert.AreEqual(preRunTempDirFileCount, Directory.GetFiles(sox.TempDir).Length); }
public void ConvertWavToRaw() { Sox sox = CreateSoxInstance(); ConvertOptions options = new ConvertOptions { InputFileInfo = new FileInfo { FileType = FileType.Wav, }, OutputFileInfo = new FileInfo { FileType = FileType.RawUnsignedInteger8, Channels = 1, SampleSizeInBits = 8, SamplingRate = 8000, EncodingType = EncodingType.UnsignedInteger } }; int preRunTempDirFileCount = Directory.GetFiles(sox.TempDir).Length; using (Stream input = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh.wav")) using (Stream expected = GetType().Assembly.GetManifestResourceStream("SoxLib.Test.Unit.doh-wav.u8")) using (Stream output = sox.Convert(input, options)) { StreamTestHelper.AssertAreEqual(expected, output, 2); } Assert.AreEqual(preRunTempDirFileCount, Directory.GetFiles(sox.TempDir).Length); }