-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
81 lines (66 loc) · 1.77 KB
/
main.go
File metadata and controls
81 lines (66 loc) · 1.77 KB
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
package main
import (
"io/ioutil"
"log"
"os"
"os/signal"
"github.com/garlicgarrison/go-recorder/recorder"
"github.com/garlicgarrison/go-recorder/stream"
"github.com/garlicgarrison/go-recorder/vad"
"github.com/garlicgarrison/mygpt-cli/voice"
"github.com/sashabaranov/go-openai"
"gopkg.in/yaml.v2"
eleven "github.com/garlicgarrison/elevenlabs2/client"
)
func main() {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, os.Kill)
file, err := os.Open("config/openai.yaml")
if err != nil {
log.Fatalf("failed to open YAML file: %v", err)
}
defer file.Close()
// Read the file content
content, err := ioutil.ReadAll(file)
if err != nil {
log.Fatalf("failed to read YAML file: %v", err)
}
// Unmarshal the YAML content
var config map[string]string
if err := yaml.Unmarshal(content, &config); err != nil {
log.Fatalf("failed to unmarshal YAML file: %v", err)
}
// Get the value of the OPENAI_API_KEY key
openaiAPIKey, ok := config["OPENAI_API_KEY"]
if !ok {
log.Fatalf("OPENAI_API_KEY key not found in YAML file")
}
client := openai.NewClient(openaiAPIKey)
stream, err := stream.NewStream(stream.DefaultStreamConfig())
if err != nil {
log.Fatalf("stream error -- %s", err)
}
rCfg := &recorder.RecorderConfig{
SampleRate: 22050,
InputChannels: 1,
FramesPerBuffer: 64,
MaxTime: 100000,
VADConfig: vad.DefaultVADConfig(),
}
recorder, err := recorder.NewRecorder(rCfg, stream)
if err != nil {
log.Fatalf("recorder error -- %s", err)
}
elevenAPIKey, ok := config["ELEVENLABS_API_KEY"]
if !ok {
log.Fatalf("ELEVENLABS_API_KEY key not found in YAML file")
}
elevenClient := eleven.New(elevenAPIKey)
vc := voice.NewVoice(client, &elevenClient, recorder)
go vc.Start()
select {
case <-sig:
vc.Close()
os.Exit(0)
}
}