-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
84 lines (67 loc) · 1.83 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
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
/*
Installation:-
Copy the libspeechdwrapper.so(in the lib folder) file to /usr/lib like this:-
sudo cp ./lib/libspeechdwrapper.so /usr/lib
Building Shared Library(Optional):-
Use the following command to generate the shared library:-
go build -buildmode=c-shared -o ./lib/libspeechdwrapper.so .
*/
package main
import "C"
import (
"github.com/ilyapashuk/go-speechd"
)
var _spd *speechd.SpeechdSession = nil
/**
* Description: Connects with the speechd socket. If no screen reader is activated, it fails to connect on the first try although if we again try to initialize after 3-4 seconds, it connects successfully.
* Return: 1 if successful and -1 if unsuccessful.
*/
//export Initialize
func Initialize() int {
spd, err := speechd.Open()
if err != nil {
print("\nError encountered while initializing speech dispatcher:\n\t" + err.Error() + "\n")
return -1
}
_spd = spd
return 1
}
/**
* Description: Speaks the given text.
* Parameters: text = the text to speak. Important!! string variable is accessed in other languages in a special way, refer to https://github.com/vladimirvivien/go-cshared-examples for examples
* interrupt = whether to cancel the previous speech or not.
* Return: 1 if successful and -1 if unsuccessful.
*/
//export Speak
func Speak(text string, interrupt bool) int {
if _spd == nil {
return -1
}
if interrupt {
_spd.Stop()
_spd.Cancel()
}
_, err := _spd.Speak(text)
if err != nil {
print("\nError encountered while speaking with speech dispatcher:\n\t" + err.Error() + "\n")
return -1
}
return 1
}
/**
* Description: Disconnects with the speechd socket.
* Return: 1 if successful and -1 if unsuccessful.
*/
//export Close
func Close() int {
if _spd == nil {
return -1
}
_spd.Close()
return 1
}
func main() {
Initialize()
Speak("Hello World", true)
Close()
}