Record audio on Windows

332 views
Skip to first unread message

Dominik Link

unread,
Sep 21, 2016, 8:32:00 AM9/21/16
to golang-nuts
Hi

I'm currently writing a program which listens to a HID (sliders and buttons) and controls a karaoke program with these inputs. Grabbing input and sending commands with websockets work, but now I need to record the audio output as well.

I tried to compile and run portaudio, but I cannot install the golang wrapper (https://github.com/gordonklaus/portaudio) as it always returns with the following error: 
"C:/Program Files/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lportaudio
collect2.exe: error: ld returned 1 exit status "

Does anyone know a simple way to record audio output using go on Windows 10? I don't want to tinker lots of hours to finally surrender anymore.

Regards,
Dominik
Message has been deleted

Dominik Link

unread,
Sep 26, 2016, 2:59:47 AM9/26/16
to golang-nuts
I solved it by using ffmpeg:

inputDeviceName := "Microphone (Realtek High Definition Audio)"
outputFile := "recording.mp3"

cmd := exec.Command("C:/Dev/ffmpeg/bin/ffmpeg.exe", "-f","dshow", "-i","audio=" + inputDeviceName, outputFile)

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin

err := cmd.Start()
if err != nil {
  println(err.Error())
}

err = cmd.Wait()
if err != nil {
  println(err.Error())
}

It works quite well. Also killing the process using cmd.Process.Kil() stops it successfully as the file will be written correctly.
Reply all
Reply to author
Forward
0 new messages