Convert vox file to wav file in Csharp-vox to wav file conversion

Convert vox file to wav format in C# or Play vox file using C#

0
1439

Convert vox file to wav file in Csharp-vox to wav file conversion

Convert vox file to wav format in C# or Play vox file using C#

There are so many solutions/tools availale to convert the vox files or to play the vox files.
I found two convertion tools which are best to use as a converter to convert .vox file to wav file.

I mentioned those 2 tools as below. The main beauty is, they provide source code in C# to convert vox file to wav using C#.

1. sox

You can use sox, to convert vox into wav file using C#. Kindly use the below coding to converting vox file to wav file format.

Create a .NET web application or windows appilcation based on your necessity.
Am considering you are using .NET windows application.

First add the below code in web.config or app.config inside <appsettings>.

<appSettings>
<add key=”SoxFilePath” value=”C:\file\sox-14-4-1\sox.exe” />
</appSettings>

Create a form and add one textbox named “txtFileName” and button named as “btnFileUpload”.

Add the below namespaces and necessary references:

using System;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using System.Net.Http;
using System.Net.Http.Headers;

Then write the below coding in the button click event.

private void btnFileUpload_Click(object sender, EventArgs e)
{
OpenFileDialog op1 = new OpenFileDialog();
op1.Multiselect = true;
op1.ShowDialog();
op1.Filter = “allfiles|*.vox”;
txtFileName.Text = op1.FileName;
int count = 0;
string[] FName;
string destfilename = “”;
//If you upload multipe file, the belwo for each is used to loop through
foreach (string s in op1.FileNames)
{
FName = s.Split(‘\\’);
File.Copy(s, “C:\\file\\” + FName[FName.Length – 1]);
destfilename = “C:\\file\\” + FName[FName.Length – 1];
count++;
}
string sourceFullPath = txtFileName.Text;
string destFullPath = destfilename.Replace(“vox”, “wav”);
var soxProcInf = GetSoxProcInf(sourceFullPath, destFullPath);
using (var soxProc = Process.Start(soxProcInf))
{
if (!soxProc.WaitForExit(5000))
soxProc.Kill();
}
//check the conversion result
if (!File.Exists(destFullPath))
throw new Exception(“Conversion using SOX seems to have failed. No converted file is found.”);
//read the wav bytes
var wavBytes = File.ReadAllBytes(destFullPath);
var mime = “audio/x-wav”;
HttpResponseMessage result = new HttpResponseMessage();
result.Content = new StreamContent(new System.IO.MemoryStream(wavBytes));
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue(“attachment”);
result.Content.Headers.ContentType = new MediaTypeHeaderValue(mime);
try
{
//If you want to delete the copied vox file from your folder, use the below code, otherwise comment it.
File.Delete(destfilename);
}
catch
{
// do nothing
}
MessageBox.Show(Convert.ToString(count) + ” File(s) copied”);
}

Then add the below method to process the vox to wav file conversion.

ProcessStartInfo GetSoxProcInf(string sourceFullPath, string destFullPath)
{
try
{
//generate files
var soxProcInf = new ProcessStartInfo();
soxProcInf.CreateNoWindow = false;
soxProcInf.UseShellExecute = false;
soxProcInf.FileName = ConfigurationManager.AppSettings[“SoxFilePath”];
soxProcInf.WindowStyle = ProcessWindowStyle.Normal;
soxProcInf.Arguments = string.Format(“\”{0}\” \”{1}\””, sourceFullPath, destFullPath);
//check for error
if (string.IsNullOrEmpty(soxProcInf.FileName))
throw new Exception(“Invalid SOX path (null/empty)”);
return soxProcInf;
}
catch (Exception ex)
{
throw;
}
}

Finally add two sox files (sox.exe and zlib1.dll) to convert the file in your folder path mentioned in config file.

Download sox-14.4.1-win32 to find the above two sox file.

There source file download link:

http://sox.sourceforge.net/

https://sourceforge.net/projects/sox/files/sox/14.4.1/

Important Note: You can use the sox.exe as free for personal use. Please check their website for license for commercial use.

2. alvas.audio.

You can download the source from their official website mentioned below:

http://www.alvas.net/alvas.audio,articles.aspx

To find the code, go the Question no. 17th (17. Vox audio file format) and get the code from the “Vox2Wav” method:

Important Note: You can use this converter as free for personal use. But you should purchase it for commercial use. Anyway read their terms of use or license.

Leave a Reply