Skip to content

Instantly share code, notes, and snippets.

@faiface
Created July 29, 2017 22:42
Show Gist options
  • Save faiface/0fdded5fde4c4fe3c054145cce8cca46 to your computer and use it in GitHub Desktop.
Save faiface/0fdded5fde4c4fe3c054145cce8cca46 to your computer and use it in GitHub Desktop.
package main
import (
"math"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
)
func main() {
f, _ := os.Open("04 Harder, Better, Faster, Stronger.mp3")
s, format, _ := mp3.Decode(f)
sr := format.SampleRate
speaker.Init(sr, sr.N(time.Second/30))
start := time.Now()
speaker.Play(beep.Iterate(func() beep.Streamer {
speedChange := (math.Sin(time.Since(start).Seconds()/2)+1)*1.5 + 0.5
newSampleRate := beep.SampleRate(float64(sr) / speedChange)
return beep.Resample(4, sr, newSampleRate, beep.Take(sr.N(time.Second/5), s))
}))
select {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment