I would like to interface with the output of my computer's audio and generate a visualization of that audio with fft's.
My question is "Where do I get the audio output stream of my computer? Are there any useful libraries for this purpose?" All the examples I've looked at stream from files, which isn't very useful to me.
I'm hoping to work in golang and linux.
Make sure that your Mac and speaker are on the same Wi-Fi or Ethernet network. Open Apple Music on your Mac. To the right of the volume slider in Apple Music, click AirPlay . Click each speaker or TV that you want to play the current audio to.
In Spotlight, open “Audio Midi Setup”. At the bottom left, create a new Multi-Output Device. And for the new multi-output device, select the devices you want audio to play through to. And finally back in Sound System Preferences, set the output device to Multi-Output Device.
The BluOS Controller app is available for Android, iOS, iPadOS, WatchOS, MacOS, Windows and Fire OS. You can download the BluOS Controller app for free using your smartphone, tablet or computer here.
Have a look at the "Graphics and Audio" and "Audio" sections of http://go-lang.cat-v.org/library-bindings.
Especially the bindings to PortAudio (http://code.google.com/p/portaudio-go/) and PulseAudio (https://github.com/moriyoshi/pulsego/) could be of use to you, being a linux guy.
For playing back sound with golang you can use beep: http://github.com/faiface/beep , see the tutorial:
package main
import (
"log"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
)
func main() {
f, err := os.Open("../Lame_Drivers_-_01_-_Frozen_Egg.mp3")
if err != nil {
log.Fatal(err)
}
streamer, format, err := mp3.Decode(f)
if err != nil {
log.Fatal(err)
}
defer streamer.Close()
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
done := make(chan bool)
speaker.Play(beep.Seq(streamer, beep.Callback(func() {
done <- true
})))
<-done
}
For recording your computers audio (microphone), you could try this tutorial: https://medium.com/@valentijnnieman_79984/how-to-build-an-audio-streaming-server-in-go-part-1-1676eed93021 that uses the PortAudio bindings:
package main
import (
"encoding/binary"
"github.com/gordonklaus/portaudio"
"net/http"
)
const sampleRate = 44100
const seconds = 1
func main() {
portaudio.Initialize()
defer portaudio.Terminate()
buffer := make([]float32, sampleRate * seconds)
stream, err := portaudio.OpenDefaultStream(1, 0, sampleRate, len(buffer), func(in []float32) {
for i := range buffer {
buffer[i] = in[i]
}
})
if err != nil {
panic(err)
}
stream.Start()
defer stream.Close()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With