-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictation.go
94 lines (85 loc) · 2.28 KB
/
dictation.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
package julius
import (
"fmt"
"log"
"os"
"os/user"
"path/filepath"
"github.com/pkg/errors"
)
type dictationKit struct {
kit string
url string
ext string
archiver string
opt string
filename string
}
var DictationModelNames = []string{
"std-gmm",
"std-dnn",
"ssr-dnn",
}
var configs = map[string]dictationKit{
"std-gmm": {
kit: "dictation-kit-v4.3.1-osx",
url: "https://ja.osdn.net/frs/redir.php?m=jaist&f=julius%2F60416%2Fdictation-kit-v4.3.1-osx.tgz",
ext: "tgz",
archiver: "tar xvzf",
opt: "-C",
filename: "am-gmm.jconf",
},
"std-dnn": {
kit: "dictation-kit-v4.3.1-osx",
url: "https://ja.osdn.net/frs/redir.php?m=jaist&f=julius%2F60416%2Fdictation-kit-v4.3.1-osx.tgz",
ext: "tgz",
archiver: "tar xvzf",
opt: "-C",
filename: "am-dnn.jconf",
},
"ssr-dnn": {
kit: "ssr-kit-v4.4.2.1a",
url: "https://ja.osdn.net/frs/redir.php?m=iij&f=julius%2F68910%2Fssr-kit-v4.4.2.1a.zip",
ext: "zip",
archiver: "unzip",
opt: "-dnnconf",
filename: "main.dnnconf",
},
}
const downloadMsg = `
ディクテーションモデル %s が見つかりません。
%s
からディクテーションキットのアーカイブをダウンロードし、展開したディレクトリを
%s
に配置して下さい。以下のコマンドで実行できます。
mkdir -p ~/.talklistener; cd ~/.talklistener; curl -vLo %s.%s '%s' && %s %s.%s
`
func Dictate(wavfile, model string) (*Result, error) {
log.Print("info: 発話内容を推定中...")
u, err := user.Current()
if err != nil {
return nil, errors.Wrap(err, "ホームディレクトリを特定できません")
}
datadir := filepath.Join(u.HomeDir, ".talklistener")
conf, ok := configs[model]
if !ok {
return nil, fmt.Errorf("ディクテーションモデル %s は定義されていません", model)
}
kitdir := filepath.Join(datadir, conf.kit)
kit := filepath.Join(kitdir, conf.filename)
if _, err := os.Stat(kit); err != nil {
return nil, fmt.Errorf(downloadMsg[1:],
model, conf.url, kitdir,
conf.kit, conf.ext, conf.url,
conf.archiver, conf.kit, conf.ext,
)
}
argv := []string{
"julius",
"-C", filepath.Join(kitdir, "main.jconf"),
conf.opt, kit,
"-palign",
"-input", "file",
}
return run(argv, wavfile)
}