Audio stream from OS

I would like to interact with the output of my computer audio and generate a visualization of this sound using fft.

My question is: "Where can I get the audio output stream of my computer? Are there any useful libraries for this purpose?" All the examples that I looked from files that are not very useful to me.

I hope to work in golang and linux.

+6
source share
3 answers

See the Graphics and Audio and Audio sections of http://go-lang.cat-v.org/library-bindings .

In particular, bindings to PortAudio ( http://code.google.com/p/portaudio-go/ ) and PulseAudio ( https://github.com/moriyoshi/pulsego/ ) can be useful to you as a linux guy.

+3
source

I know this was a long time ago, but if anyone else asks a question, I worked on: https://github.com/padster/go-sound

Sounds are modeled as channels of samples with a floating point (44.1khz, each sample in the range [-1, 1]), and you can process them, or, for example, play in speakers (currently via pulsego), write them to a file or display using openGL.

There is also an experimental FFT code (constant Q, which is similar)

0
source

To play sound using golang, you can use the sound signal: 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 } 

To record sound from your computer (microphone), you can try this guide: https://medium.com/@valentijnnieman_79984/how-to-build-an-audio-streaming-server-in-go-part-1-1676eed93021, which uses 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() } 
0
source

Source: https://habr.com/ru/post/1215631/


All Articles