-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaquestalk_linux.go
53 lines (46 loc) · 1.26 KB
/
aquestalk_linux.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
package aquestalk
import (
"errors"
"fmt"
"unsafe"
)
/*
#cgo LDFLAGS: -ldl
#include <dlfcn.h>
unsigned char* callSynthe(void *p, const char *koe, int speed, int *size) {
unsigned char* (*synthe)(const char*, int, int*) = p;
return synthe(koe, speed, size);
}
void callFree(void *p, unsigned char *wav) {
void (*freewav)(unsigned char *) = p;
freewav(wav);
}
*/
import "C"
// DLLName declares name of shared object. You can change this only before call Synthe().
var DLLName = "./libAquesTalk.so"
// Synthe synthesizes voice with an engine a.k.a. "Yukkuri".
func Synthe(koe string, speed int32) ([]byte, error) {
h := C.dlopen(C.CString(DLLName), C.RTLD_LAZY)
if h == nil {
return nil, fmt.Errorf("failed to load %s", DLLName)
}
pSynthe := C.dlsym(h, C.CString("AquesTalk_Synthe_Utf8"))
if pSynthe == nil {
return nil, errors.New("not found symbol: AquesTalk_Synthe_Utf8")
}
pFree := C.dlsym(h, C.CString("AquesTalk_FreeWave"))
if pFree == nil {
return nil, errors.New("not found symbol: AquesTalk_FreeWave")
}
var size C.int
r := C.callSynthe(pSynthe, C.CString(koe), C.int(speed), &size)
if r == nil {
return nil, errno(size)
}
pWav := C.GoBytes(unsafe.Pointer(r), size)
p := make([]byte, len(pWav))
copy(p, pWav)
C.callFree(pFree, r)
return p, nil
}