Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio Streaming from OS

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.

like image 264
facetiousfactorial Avatar asked Mar 18 '15 22:03

facetiousfactorial


People also ask

How do I stream audio from my Mac?

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.

How do I stream audio from one Mac to another?

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.

What devices use BluOS?

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.


2 Answers

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.

like image 104
Peter Brennan Avatar answered Oct 13 '22 16:10

Peter Brennan


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()
}
like image 2
Simon Epskamp Avatar answered Oct 13 '22 17:10

Simon Epskamp