-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (40 loc) · 851 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
hook "github.com/robotn/gohook"
)
func main() {
add()
}
func add() {
f, err := os.Open("./audio/down.mp3")
if err != nil {
log.Fatal(err)
}
streamer, format, err := mp3.Decode(f)
if err != nil {
log.Fatal(err)
}
fmt.Println("Press any key ---")
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/100))
buffer := beep.NewBuffer(format)
buffer.Append(streamer)
streamer.Close()
done := make(chan bool)
hook.Register(hook.KeyDown, []string{}, func(e hook.Event) {
fmt.Println(e.Keychar, e.Keycode)
shot := buffer.Streamer(0, buffer.Len())
speaker.Play(beep.Seq(shot, beep.Callback(func() {
done <- true
})))
})
<-done
s := hook.Start()
<-hook.Process(s)
}