Home > Uncategorized > Using SoundeXchange to convert MP3 to WAV for #Lync and #MSExchange

Using SoundeXchange to convert MP3 to WAV for #Lync and #MSExchange

When working with Lync and Exchange I regularly find myself needing to convert MP3 files to WAV files for the specific need of UM.  Typically, this involves finding the right bit rate, etc.  After finding a command line tool (SoundeXchange) to do this, I naturally wanted it even easier so I created a function in PowerShell to do just that.

In order to run this script, you do need a few pre-reqs.  First, you need to install SoundeXchange.  You can download it from here: http://sox.sourceforge.net.  My script is based on version 14.4.0 and I believe there is a newer version out so change the script below to fit the version you install.

Next, you need to have the libmad.dll file placed in the SoX directory (you will need to find libmad.dll on the Internet as I cannot host it).

Now that you have those two pieces, here is the script:

###########################################################
#
# Convert-MP32Wav
# By: Adam Ball
# Date: 03/15/2013
# Version 1.1
#
# NOTE: Assumes you have SoundXchange installed in "C:\Program Files (x86)\sox-14-4-0"
#
# History:
# 1.0 Initial Script that allows you to choose a file
# 1.1 Changed the script to be a function that accepts an input
#
# Example:
# convert-mp32wav -filename my_audio_recording.mp3
#
##########################################################

# Function to open a File Dialog box to choose the filename
Function Get-FileName($initialDirectory)
{
 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null

 $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
 $OpenFileDialog.initialDirectory = $initialDirectory
 $OpenFileDialog.filter = "All files (*.*)| *.*"
 $OpenFileDialog.ShowDialog() | Out-Null
 $OpenFileDialog.filename
 } #end function Get-FileName

# *** Entry Point to Script ***
Function Convert-MP32Wav
{
 param($filename)

 $mp3file = $filename

 If ($mp3file -eq $null){

   If ((Test-Path "C:\Program Files (x86)\sox-14-4-0") -eq $true){

   $initdirectory = $env:USERPROFILE + "\Documents"

   # Get the file you want to convert
   $mp3file = Get-FileName -initialDirectory $initdirectory

   # Change the Filename from MP3 to WAV
   $newfilename = $mp3file.replace("mp3","wav")

   & "C:\Program Files (x86)\sox-14-4-0\sox.exe" $mp3file -r 8000 -c1 $newfilename
 }
 Else {
      Write "You need to install SoundXchange"
      }
 }
 Else {
     If ((Test-Path "C:\Program Files (x86)\sox-14-4-0") -eq $true){

     # Change the Filename from MP3 to WAV
     $newfilename = $mp3file.replace("mp3","wav")

     & "C:\Program Files (x86)\sox-14-4-0\sox.exe" $mp3file -r 8000 -c1 $newfilename
     }
     Else {
          Write "You need to install SoundXchange"
          }
     }
}
Advertisements
Categories: Uncategorized Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: