-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
129 lines (102 loc) · 2.44 KB
/
utils.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"bytes"
"embed"
"fmt"
"image/jpeg"
"io/fs"
"log"
"os/exec"
"runtime"
"strings"
"github.com/kbinani/screenshot"
)
//go:embed web
var embeddedFiles embed.FS
func Screenshot() ([]byte, error) {
n := 0
if screenshot.NumActiveDisplays() != 0 {
n = 0
}
bounds := screenshot.GetDisplayBounds(n)
img, err := screenshot.CaptureRect(bounds)
if err != nil {
return nil, err
}
buffer := new(bytes.Buffer)
err = jpeg.Encode(buffer, img, nil)
if err != nil {
return nil, err
}
imageBytes := buffer.Bytes()
return imageBytes, nil
}
func SpeakMessage(message string, stopSpeech chan struct{}) {
// Use appropriate text-to-speech command based on OS
var cmd *exec.Cmd
switch runtime.GOOS {
case "darwin":
cmd = exec.Command("say", message)
case "windows":
cmd = exec.Command("powershell", "-c", "Add-Type -AssemblyName System.Speech; $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer; $speak.Speak('"+message+"')")
case "linux":
cmd = exec.Command("spd-say", message)
default:
fmt.Println("Text-to-speech not supported on this platform")
return
}
// Start command asynchronously
if err := cmd.Start(); err != nil {
fmt.Println("Error starting speech:", err)
return
}
// Create a channel to signal command completion
done := make(chan error)
go func() {
done <- cmd.Wait()
}()
// Wait for either command completion or stop signal
select {
case err := <-done:
if err != nil {
fmt.Println("Error speaking message:", err)
}
case <-stopSpeech:
// Kill the process if stop signal received
if err := cmd.Process.Kill(); err != nil {
fmt.Println("Failed to stop speech:", err)
}
}
}
func PutTextOnClipboard(data string) error {
// Use appropriate clipboard command based on OS
var cmd *exec.Cmd
switch runtime.GOOS {
case "darwin":
cmd = exec.Command("pbcopy")
case "windows":
cmd = exec.Command("clip")
case "linux":
cmd = exec.Command("xclip", "-selection", "c")
default:
fmt.Println("Clipboard not supported on this platform")
return nil
}
cmd.Stdin = strings.NewReader(data)
if err := cmd.Run(); err != nil {
return err
}
return nil
}
func RecordAudio(seconds int) ([]byte, error) {
audioBytes := []byte{}
return audioBytes, nil
}
func getEmbeddedWebFS() fs.FS {
// Get the filesystem for the embedded web directory
fs, err := fs.Sub(embeddedFiles, "web")
if err != nil {
log.Fatalf("Error getting embedded web filesystem: %v", err)
}
return fs
}