-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (34 loc) · 865 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
package main
import (
"fmt"
"github.com/dairaga/js"
"github.com/dairaga/js/dom"
"github.com/dairaga/js/media"
"github.com/dairaga/js/media/recorder"
)
//var stream = media.Stream{}
var rec *recorder.Recorder
var ctx *media.AudioContext
func main() {
dom.S("#record").OnClick(func(_ *dom.Element, _ *js.Event) {
media.GetUserMedia(media.StreamConstrains{Audio: true, Video: false},
func(s *media.Stream) {
ctx = media.NewAudioContext(16000)
rec = recorder.New(ctx.CreateMediaStreamSource(s), media.Size4096, 1)
rec.OnRecording(func(data []float32) {
fmt.Println(data)
})
fmt.Println("sample rate from audio context:", ctx.SampleRate())
rec.Record()
},
func(err *js.Error) {
fmt.Println(err)
},
)
})
dom.S("#stop").OnClick(func(_ *dom.Element, _ *js.Event) {
rec.Stop()
ctx.Close()
})
select {}
}