Created
July 29, 2020 02:00
-
-
Save duhdugg/87d6c946dee20366df328e8447001e9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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