-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.go
48 lines (39 loc) · 1.09 KB
/
screen.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 (
"context"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/go-vgo/robotgo"
)
// capture screen and ask openai to describe it, cleans up any temp files
func describeScreen(ctx context.Context) (string, error) {
// Take a screenshot
path, err := takeScreenshot()
if err != nil {
return "", fmt.Errorf("Error taking screenshot: %v", err)
}
defer os.Remove(path)
// Describe the image
description, err := describeImage(ctx, path)
if err != nil {
return "", fmt.Errorf("Error describing image: %v", err)
}
return description, nil
}
// capture a screenshot of the display and save it to a temporary file
func takeScreenshot() (string, error) {
image := robotgo.CaptureImg()
tempFile, err := ioutil.TempFile("", fmt.Sprintf("talkxtyper-%d-*.png", time.Now().Unix()))
if err != nil {
return "", fmt.Errorf("Error creating temporary file: %v", err)
}
defer tempFile.Close()
// Save the screenshot to the temporary file
err = robotgo.Save(image, tempFile.Name())
if err != nil {
return "", fmt.Errorf("Error saving screenshot: %v", err)
}
return tempFile.Name(), nil
}