Golang Implementing WAV files to MP3 files

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.