This is a creation in Article, where the information may have evolved or changed.
Instead of Golang a built-in library for WAV-MP3, this article transforms it by Golang calling the lame command of Linux.
In a Linux environment, lame is not installed by default, so you first need to install lame (personal save download file: Http://pan.baidu.com/s/1qWp71G4#path=%252Fsharesoft%252Flinux%252Flame).
Linux lame Installation and use:
1. Unzip lame compressed file: TAR-VZXF lame-3.98.4.tar.gz
2. Go to the extracted files directory, then execute: "./configure--enable-shared", "make", "Make Install"
3. How to use lame: lame xxx.wav xxx.mp3 (so you can convert xxx.wav files to Xxx.mp3 files)
The next step is to invoke the Linux Lame command via Golang to implement the WAV mp3.
1 Package Main2 3 Import (4 "Log"5 "OS"6 "os/exec"7 )8 9 Func Main () {TenWav_file: ="/root/input.wav" //wav files that need to be converted OneMp3_file: ="/root/output.mp3" //MP3 file storage path after conversion ACMD: = Exec.command ("lame", Wav_file, Mp3_file) -ERR: =cmd. Run () - ifErr! =Nil { theLog. Fatal ("Convert wav to MP3 error.", Err) - return - } - //wav to mp3 successful, if necessary, you can delete the WAV original file + OS. Remove (Wav_file) - } + A //successfully converted WAV files to MP3 file at //Original WAV file size: 97.70KB - //converted mp3 File size: 9.79KB