-
Notifications
You must be signed in to change notification settings - Fork 1
/
tts.go
123 lines (105 loc) · 2.18 KB
/
tts.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
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"syscall"
)
func dxecute(tmp *os.File, cmd ...string) {
b := []string{"sh", "-c"}
b = append(b, cmd...)
b = append(b, tmp.Name())
fmt.Println(b)
exe := exec.Command(b[0], b[1], "'", "amy", "-f", tmp.Name(), "'")
exe.Run()
}
func Execute(tmp *os.File) {
exe := exec.Command("amy", "-f", tmp.Name())
exe.Run()
}
func runCtx(cmd ...string) *os.Process {
b := []string{"sh", "-c"}
b = append(b, cmd...)
exe := exec.Command(b[0], b[1:]...)
exe.Run()
return exe.Process
}
func pauseTTS(pr *os.Process) error {
err := pr.Signal(syscall.SIGSTOP)
return err
}
func continueTTS(pr *os.Process) error {
err := pr.Signal(syscall.SIGCONT)
return err
}
func stopTTS(pr *os.Process) error {
err := pr.Signal(syscall.SIGKILL)
return err
}
func system(cmd string) int {
c := exec.Command("sh", "-c", cmd)
c.Env = os.Environ()
// c.Env = append(c.Env, env_vars)
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err := c.Run()
if err == nil {
return 0
}
// Figure out the exit code
if ws, ok := c.ProcessState.Sys().(syscall.WaitStatus); ok {
if ws.Exited() {
return ws.ExitStatus()
}
if ws.Signaled() {
return -int(ws.Signal())
}
}
return -1
}
func startTTS(t string, c string) {
dir, err := os.Getwd()
if err != nil {
fmt.Println(err)
}
tmp, _ := os.CreateTemp(dir, "tts_")
tmp.Write([]byte(t))
tmp.Close()
// cmd := strings.ReplaceAll(command, "{{file}}", tmp.Name())
defer os.Remove(tmp.Name())
out := exec.Command("balcon", "-i", "-n", "Amy")
out.Env = os.Environ()
p, err := out.StdinPipe()
p.Write([]byte(t))
out.Stdout = os.Stdout
out.Stderr = os.Stderr
out.Run()
if err != nil {
fmt.Println(err)
}
fmt.Println(out)
}
func tts_stdin(t string, c string) {
dir, err := os.Getwd()
if err != nil {
fmt.Println(err)
}
tmp, _ := os.CreateTemp(dir, "tts_")
tmp.Write([]byte(t))
tmp.Close()
defer os.Remove(tmp.Name())
cmd := strings.Split(command, " ")
out := exec.Command(cmd[0], cmd[1:]...)
out.Env = os.Environ()
p, err := out.StdinPipe()
p.Write([]byte(t))
out.Stdout = os.Stdout
out.Stderr = os.Stderr
out.Run()
if err != nil {
fmt.Println(err)
}
fmt.Println(out)
}