-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
52 lines (41 loc) · 1.1 KB
/
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
49
50
51
52
// Record Windows Audio project main.go
package main
import (
"fmt"
"log"
"syscall"
"time"
"unsafe"
)
var (
winmm = syscall.MustLoadDLL("winmm.dll")
mciSendString = winmm.MustFindProc("mciSendStringW")
)
func MCIWorker(lpstrCommand string, lpstrReturnString string, uReturnLength int, hwndCallback int) uintptr {
i, _, _ := mciSendString.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpstrCommand))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpstrReturnString))),
uintptr(uReturnLength), uintptr(hwndCallback))
return i
}
func main() {
fmt.Println("winmm.dll Record Audio to .wav file")
i := MCIWorker("open new type waveaudio alias capture", "", 0, 0)
if i != 0 {
log.Fatal("Error Code A: ", i)
}
i = MCIWorker("record capture", "", 0, 0)
if i != 0 {
log.Fatal("Error Code B: ", i)
}
fmt.Println("Listening...")
time.Sleep(10 * time.Second)
i = MCIWorker("save capture mic.wav", "", 0, 0)
if i != 0 {
log.Fatal("Error Code C: ", i)
}
i = MCIWorker("close capture", "", 0, 0)
if i != 0 {
log.Fatal("Error Code D: ", i)
}
fmt.Println("Audio saved to mic.wav")
}