Skip to content

Instantly share code, notes, and snippets.

@duhdugg
Created July 29, 2020 02:00
Show Gist options
  • Save duhdugg/87d6c946dee20366df328e8447001e9e to your computer and use it in GitHub Desktop.
Save duhdugg/87d6c946dee20366df328e8447001e9e to your computer and use it in GitHub Desktop.
/* first, "go get" these dependencies:
github.com/faiface/beep
github.com/hajimehoshi/oto
*/
package main
import (
"fmt"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
"log"
"os"
"time"
)
func main() {
f, err := os.Open("./assets/day-tripper.mp3")
if err != nil {
log.Fatal(err)
}
streamer, format, err := mp3.Decode(f)
if err != nil {
log.Fatal(err)
}
defer streamer.Close()
steps := -7
sr := beep.SampleRate(float64(format.SampleRate) * (float64(steps)/12 + 1))
fmt.Println("original sample rate", format.SampleRate)
fmt.Println(" new sample rate", sr)
speaker.Init(sr, sr.N(time.Second/10))
speaker.Play(streamer)
select {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment