Skip to content

Commit 909fbd3

Browse files
authored
Merge pull request #1 from ultreme/poc
V1 pronounce
2 parents a6187b0 + 341fde5 commit 909fbd3

File tree

205 files changed

+255
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+255
-14
lines changed

.circleci/config.yml

-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,4 @@ workflows:
88
jobs:
99
- moul/golang-build:
1010
gopkg: ultre.me/speechotron
11-
- moul/golang-build:
12-
gopkg: ultre.me/speechotron
13-
tag: '1.12'
14-
- moul/golang-build:
15-
gopkg: ultre.me/speechotron
16-
tag: '1.11'
1711
- moul/docker-build

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.DS_Store
2+
out.mp3
3+
14
# Temporary files
25
*~
36
*#

go.mod

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.sum

+87
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.go

+160-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,165 @@
11
package main
22

3-
import "fmt"
3+
import (
4+
"errors"
5+
"flag"
6+
"fmt"
7+
"log"
8+
"math/rand"
9+
"os"
10+
"os/exec"
11+
"sort"
12+
"strings"
13+
14+
packr "github.com/gobuffalo/packr/v2"
15+
"github.com/peterbourgon/ff/ffcli"
16+
)
17+
18+
var (
19+
sayBox = packr.New("say", "./say")
20+
pronounceBox = packr.New("pronounce", "./pronounce")
21+
)
422

523
func main() {
6-
fmt.Println("Hello World!")
24+
log.SetFlags(0)
25+
26+
var (
27+
sayFlags = flag.NewFlagSet("say", flag.ExitOnError)
28+
sayVoice = sayFlags.String("v", "RANDOM", "voice")
29+
30+
pronounceFlags = flag.NewFlagSet("pronounce", flag.ExitOnError)
31+
pronounceVoice = pronounceFlags.String("v", "RANDOM", "voice")
32+
)
33+
34+
pronounce := &ffcli.Command{
35+
Name: "pronounce",
36+
Usage: "pronounce [-v VOICE] PRONOUNCE",
37+
FlagSet: pronounceFlags,
38+
LongHelp: fmt.Sprintf("VOICES\n %s", strings.Join(append(voiceList(pronounceBox), "RANDOM"), "\n ")),
39+
Exec: func(args []string) error {
40+
if len(args) < 1 {
41+
return flag.ErrHelp
42+
}
43+
parts := voiceParts(pronounceBox, *pronounceVoice)
44+
45+
tosay := []rune(strings.Join(args, " "))
46+
47+
selectedParts := []string{}
48+
49+
for i := 0; i < len(tosay); {
50+
maxLen := 0
51+
selectedPart := ""
52+
for partString := range parts {
53+
part := []rune(partString)
54+
if len(part) <= maxLen {
55+
continue
56+
}
57+
if string(part) == string(tosay[i:i+len(part)]) {
58+
maxLen = len(part)
59+
selectedPart = string(part)
60+
}
61+
}
62+
if selectedPart != "" {
63+
i += maxLen
64+
selectedParts = append(selectedParts, selectedPart)
65+
} else {
66+
i++ // skip unmatched parts
67+
}
68+
}
69+
70+
selectedFiles := []string{}
71+
72+
for _, part := range selectedParts {
73+
randomFile := parts[part][rand.Intn(len(parts[part]))]
74+
selectedFiles = append(selectedFiles, fmt.Sprintf("./pronounce/%s", randomFile))
75+
}
76+
77+
cmdArgs := append(selectedFiles, "out.mp3")
78+
log.Printf("+ sox %s", strings.Join(cmdArgs, " "))
79+
cmd := exec.Command("sox", cmdArgs...)
80+
cmd.Stdout = os.Stdout
81+
cmd.Stderr = os.Stderr
82+
if err := cmd.Run(); err != nil {
83+
return err
84+
}
85+
86+
log.Printf("+ afplay out.mp3")
87+
cmd = exec.Command("afplay", "out.mp3")
88+
if err := cmd.Run(); err != nil {
89+
return err
90+
}
91+
92+
return nil
93+
},
94+
}
95+
96+
say := &ffcli.Command{
97+
Name: "say",
98+
Usage: "say [-v VOICE] SAY",
99+
FlagSet: sayFlags,
100+
LongHelp: fmt.Sprintf("VOICES\n %s", strings.Join(append(voiceList(sayBox), "RANDOM"), "\n ")),
101+
Exec: func(args []string) error {
102+
if len(args) < 1 {
103+
return flag.ErrHelp
104+
}
105+
_ = sayVoice
106+
return fmt.Errorf("not implemented")
107+
},
108+
}
109+
110+
root := &ffcli.Command{
111+
Usage: "speechotron <subcommand> [flags] [args...]",
112+
Subcommands: []*ffcli.Command{pronounce, say},
113+
Exec: func([]string) error { return flag.ErrHelp },
114+
}
115+
116+
if err := root.Run(os.Args[1:]); err != nil {
117+
if errors.Is(err, flag.ErrHelp) {
118+
return
119+
}
120+
log.Fatalf("fatal: %+v", err)
121+
}
122+
}
123+
124+
func voiceList(box *packr.Box) []string {
125+
voices := map[string]bool{}
126+
for _, voice := range box.List() {
127+
if !strings.HasSuffix(voice, ".wav") {
128+
continue
129+
}
130+
voices[strings.Split(voice, "/")[0]] = true
131+
}
132+
133+
ret := []string{}
134+
for voice := range voices {
135+
ret = append(ret, voice)
136+
}
137+
sort.Strings(ret)
138+
139+
return ret
140+
}
141+
142+
func voiceParts(box *packr.Box, voice string) map[string][]string {
143+
ret := map[string][]string{}
144+
145+
for _, file := range box.List() {
146+
if !strings.HasSuffix(file, ".wav") {
147+
continue
148+
}
149+
150+
spl := strings.Split(file, "/")
151+
actualVoice := spl[0]
152+
if voice != "RANDOM" && voice != actualVoice {
153+
continue
154+
}
155+
156+
part := strings.Replace(spl[1], ".wav", "", -1)
157+
158+
if _, ok := ret[part]; !ok {
159+
ret[part] = []string{}
160+
}
161+
ret[part] = append(ret[part], file)
162+
}
163+
164+
return ret
7165
}

main_test.go

-6
This file was deleted.

pronounce/gajeb-1/a.wav

167 KB
Binary file not shown.

pronounce/gajeb-1/b.wav

198 KB
Binary file not shown.

pronounce/gajeb-1/ch.wav

185 KB
Binary file not shown.

pronounce/gajeb-1/d.wav

189 KB
Binary file not shown.

pronounce/gajeb-1/e.wav

149 KB
Binary file not shown.

pronounce/gajeb-1/en.wav

126 KB
Binary file not shown.

pronounce/gajeb-1/f.wav

221 KB
Binary file not shown.

pronounce/gajeb-1/gu.wav

185 KB
Binary file not shown.

pronounce/gajeb-1/h.wav

284 KB
Binary file not shown.

pronounce/gajeb-1/i.wav

189 KB
Binary file not shown.

pronounce/gajeb-1/j.wav

162 KB
Binary file not shown.

pronounce/gajeb-1/k.wav

85.7 KB
Binary file not shown.

pronounce/gajeb-1/l.wav

212 KB
Binary file not shown.

pronounce/gajeb-1/m.wav

221 KB
Binary file not shown.

pronounce/gajeb-1/n.wav

230 KB
Binary file not shown.

pronounce/gajeb-1/o.wav

185 KB
Binary file not shown.

pronounce/gajeb-1/on.wav

203 KB
Binary file not shown.

pronounce/gajeb-1/ou.wav

180 KB
Binary file not shown.

pronounce/gajeb-1/p.wav

225 KB
Binary file not shown.

pronounce/gajeb-1/r.wav

203 KB
Binary file not shown.

pronounce/gajeb-1/s.wav

176 KB
Binary file not shown.

pronounce/gajeb-1/t.wav

180 KB
Binary file not shown.

pronounce/gajeb-1/u.wav

248 KB
Binary file not shown.

pronounce/gajeb-1/v.wav

131 KB
Binary file not shown.

pronounce/gajeb-1/w.wav

198 KB
Binary file not shown.

pronounce/gajeb-1/x.wav

189 KB
Binary file not shown.

pronounce/gajeb-1/z.wav

153 KB
Binary file not shown.

pronounce/gajeb-1/è.wav

223 KB
Binary file not shown.

pronounce/gajeb-1/é.wav

223 KB
Binary file not shown.

say/gajeb1/andouille.wav

238 KB
Binary file not shown.

say/gajeb1/bois.wav

162 KB
Binary file not shown.

say/gajeb1/bout.wav

170 KB
Binary file not shown.

say/gajeb1/caca.wav

124 KB
Binary file not shown.

say/gajeb1/carton.wav

16.4 MB
Binary file not shown.

say/gajeb1/chien.wav

16.4 MB
Binary file not shown.

say/gajeb1/contreplaqué.wav

196 KB
Binary file not shown.

say/gajeb1/crotte.wav

130 KB
Binary file not shown.

say/gajeb1/d'andouille.wav

150 KB
Binary file not shown.

say/gajeb1/d'arbre.wav

134 KB
Binary file not shown.

say/gajeb1/d'ectoplasme.wav

212 KB
Binary file not shown.

say/gajeb1/d'occasion.wav

172 KB
Binary file not shown.

say/gajeb1/d'oreille.wav

192 KB
Binary file not shown.

say/gajeb1/de.wav

114 KB
Binary file not shown.

say/gajeb1/ectoplasme.wav

208 KB
Binary file not shown.

say/gajeb1/en.wav

96.2 KB
Binary file not shown.

say/gajeb1/espèce.wav

250 KB
Binary file not shown.

say/gajeb1/fesse.wav

194 KB
Binary file not shown.

say/gajeb1/forbant.wav

180 KB
Binary file not shown.

say/gajeb1/formica.wav

182 KB
Binary file not shown.

say/gajeb1/freluquet.wav

162 KB
Binary file not shown.

say/gajeb1/fromage.wav

264 KB
Binary file not shown.

say/gajeb1/gigantesque.wav

250 KB
Binary file not shown.

say/gajeb1/jus.wav

132 KB
Binary file not shown.

say/gajeb1/maché.wav

208 KB
Binary file not shown.

say/gajeb1/minuscule.wav

216 KB
Binary file not shown.

say/gajeb1/moule à gauffre.wav

238 KB
Binary file not shown.

say/gajeb1/nez.wav

170 KB
Binary file not shown.

say/gajeb1/nouille.wav

180 KB
Binary file not shown.

say/gajeb1/papier.wav

172 KB
Binary file not shown.

say/gajeb1/pied.wav

182 KB
Binary file not shown.

say/gajeb1/pipi.wav

162 KB
Binary file not shown.

say/gajeb1/plat.wav

100 KB
Binary file not shown.

say/gajeb1/platre.wav

150 KB
Binary file not shown.

say/gajeb1/poubelle.wav

226 KB
Binary file not shown.

say/gajeb1/prout.wav

130 KB
Binary file not shown.

say/gajeb1/purée.wav

126 KB
Binary file not shown.

say/gajeb1/raclure.wav

200 KB
Binary file not shown.

say/gajeb1/recyclé.wav

156 KB
Binary file not shown.

say/gajeb1/résidu.wav

198 KB
Binary file not shown.

say/gajeb1/toc.wav

132 KB
Binary file not shown.

say/gajeb1/vandal.wav

170 KB
Binary file not shown.

say/gajeb1/yeux.wav

160 KB
Binary file not shown.

say/gajeb1/zizi.wav

174 KB
Binary file not shown.

words/moul2/0.wav say/moul2/0.wav

File renamed without changes.

words/moul2/1.wav say/moul2/1.wav

File renamed without changes.

words/moul2/2.wav say/moul2/2.wav

File renamed without changes.

words/moul2/3.wav say/moul2/3.wav

File renamed without changes.

words/moul2/4.wav say/moul2/4.wav

File renamed without changes.

words/moul2/5.wav say/moul2/5.wav

File renamed without changes.

words/moul2/6.wav say/moul2/6.wav

File renamed without changes.

words/moul2/7.wav say/moul2/7.wav

File renamed without changes.

words/moul2/8.wav say/moul2/8.wav

File renamed without changes.

words/moul2/9.wav say/moul2/9.wav

File renamed without changes.

words/moul2/a.wav say/moul2/a.wav

File renamed without changes.

words/moul2/c.wav say/moul2/c.wav

File renamed without changes.

words/moul2/d.wav say/moul2/d.wav

File renamed without changes.

words/moul2/e.wav say/moul2/e.wav

File renamed without changes.

words/moul2/f.wav say/moul2/f.wav

File renamed without changes.

words/moul2/g.wav say/moul2/g.wav

File renamed without changes.

words/moul2/h.wav say/moul2/h.wav

File renamed without changes.

words/moul2/i.wav say/moul2/i.wav

File renamed without changes.

words/moul2/j.wav say/moul2/j.wav

File renamed without changes.

words/moul2/k.wav say/moul2/k.wav

File renamed without changes.

words/moul2/l.wav say/moul2/l.wav

File renamed without changes.

words/moul2/m.wav say/moul2/m.wav

File renamed without changes.

words/moul2/n.wav say/moul2/n.wav

File renamed without changes.

words/moul2/o.wav say/moul2/o.wav

File renamed without changes.

words/moul2/p.wav say/moul2/p.wav

File renamed without changes.

words/moul2/q.wav say/moul2/q.wav

File renamed without changes.

words/moul2/r.wav say/moul2/r.wav

File renamed without changes.

words/moul2/s.wav say/moul2/s.wav

File renamed without changes.

words/moul2/t.wav say/moul2/t.wav

File renamed without changes.

words/moul2/u.wav say/moul2/u.wav

File renamed without changes.

words/moul2/v.wav say/moul2/v.wav

File renamed without changes.

words/moul2/w.wav say/moul2/w.wav

File renamed without changes.

words/moul2/x.wav say/moul2/x.wav

File renamed without changes.

words/moul2/y.wav say/moul2/y.wav

File renamed without changes.

words/moul2/z.wav say/moul2/z.wav

File renamed without changes.

say/silent.wav

78.2 KB
Binary file not shown.

words/vik1/!.wav say/vik1/!.wav

File renamed without changes.

words/vik1/#.wav say/vik1/#.wav

File renamed without changes.

words/vik1/$.wav say/vik1/$.wav

File renamed without changes.

words/vik1/%.wav say/vik1/%.wav

File renamed without changes.

words/vik1/&.wav say/vik1/&.wav

File renamed without changes.

words/vik1/(.wav say/vik1/(.wav

File renamed without changes.

words/vik1/).wav say/vik1/).wav

File renamed without changes.

words/vik1/+.wav say/vik1/+.wav

File renamed without changes.

words/vik1/,.wav say/vik1/,.wav

File renamed without changes.

words/vik1/-.wav say/vik1/-.wav

File renamed without changes.

words/vik1/0.wav say/vik1/0.wav

File renamed without changes.

words/vik1/1.wav say/vik1/1.wav

File renamed without changes.

words/vik1/2.wav say/vik1/2.wav

File renamed without changes.

words/vik1/3.wav say/vik1/3.wav

File renamed without changes.

words/vik1/4.wav say/vik1/4.wav

File renamed without changes.

words/vik1/5.wav say/vik1/5.wav

File renamed without changes.

words/vik1/6.wav say/vik1/6.wav

File renamed without changes.

words/vik1/7.wav say/vik1/7.wav

File renamed without changes.

words/vik1/8.wav say/vik1/8.wav

File renamed without changes.

words/vik1/9.wav say/vik1/9.wav

File renamed without changes.

words/vik1/;.wav say/vik1/;.wav

File renamed without changes.

words/vik1/=.wav say/vik1/=.wav

File renamed without changes.

words/vik1/@.wav say/vik1/@.wav

File renamed without changes.

words/vik1/[.wav say/vik1/[.wav

File renamed without changes.

words/vik1/].wav say/vik1/].wav

File renamed without changes.

words/vik1/^.wav say/vik1/^.wav

File renamed without changes.

words/vik1/_.wav say/vik1/_.wav

File renamed without changes.

words/vik1/a.wav say/vik1/a.wav

File renamed without changes.

words/vik1/b.wav say/vik1/b.wav

File renamed without changes.
File renamed without changes.
File renamed without changes.

words/vik1/c.wav say/vik1/c.wav

File renamed without changes.

words/vik1/d.wav say/vik1/d.wav

File renamed without changes.
File renamed without changes.
File renamed without changes.

words/vik1/e.wav say/vik1/e.wav

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

words/vik1/f.wav say/vik1/f.wav

File renamed without changes.

words/vik1/g.wav say/vik1/g.wav

File renamed without changes.

words/vik1/h.wav say/vik1/h.wav

File renamed without changes.
File renamed without changes.
File renamed without changes.

words/vik1/i.wav say/vik1/i.wav

File renamed without changes.
File renamed without changes.

words/vik1/j.wav say/vik1/j.wav

File renamed without changes.

words/vik1/k.wav say/vik1/k.wav

File renamed without changes.

words/vik1/l.wav say/vik1/l.wav

File renamed without changes.
File renamed without changes.

words/vik1/m.wav say/vik1/m.wav

File renamed without changes.
File renamed without changes.

words/vik1/n.wav say/vik1/n.wav

File renamed without changes.
File renamed without changes.

words/vik1/o.wav say/vik1/o.wav

File renamed without changes.
File renamed without changes.

words/vik1/p.wav say/vik1/p.wav

File renamed without changes.
File renamed without changes.
File renamed without changes.

words/vik1/q.wav say/vik1/q.wav

File renamed without changes.
File renamed without changes.

words/vik1/r.wav say/vik1/r.wav

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

words/vik1/s.wav say/vik1/s.wav

File renamed without changes.
File renamed without changes.

words/vik1/t.wav say/vik1/t.wav

File renamed without changes.
File renamed without changes.

words/vik1/u.wav say/vik1/u.wav

File renamed without changes.

words/vik1/v.wav say/vik1/v.wav

File renamed without changes.
File renamed without changes.

words/vik1/w.wav say/vik1/w.wav

File renamed without changes.

words/vik1/x.wav say/vik1/x.wav

File renamed without changes.

words/vik1/y.wav say/vik1/y.wav

File renamed without changes.

words/vik1/z.wav say/vik1/z.wav

File renamed without changes.

words/vik1/{.wav say/vik1/{.wav

File renamed without changes.

words/vik1/}.wav say/vik1/}.wav

File renamed without changes.

words/vik1/~.wav say/vik1/~.wav

File renamed without changes.

words/vik2/0.wav say/vik2/0.wav

File renamed without changes.

words/vik2/1.wav say/vik2/1.wav

File renamed without changes.

words/vik2/2.wav say/vik2/2.wav

File renamed without changes.

words/vik2/3.wav say/vik2/3.wav

File renamed without changes.

words/vik2/4.wav say/vik2/4.wav

File renamed without changes.

words/vik2/5.wav say/vik2/5.wav

File renamed without changes.

words/vik2/6.wav say/vik2/6.wav

File renamed without changes.

words/vik2/7.wav say/vik2/7.wav

File renamed without changes.

words/vik2/8.wav say/vik2/8.wav

File renamed without changes.

words/vik2/9.wav say/vik2/9.wav

File renamed without changes.

0 commit comments

Comments
 (0)