-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_optional_audio.go
79 lines (63 loc) · 1.26 KB
/
step_optional_audio.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
package main
import (
"encoding/csv"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"time"
)
func main() {
csvFile, err := os.Open("data/init/text/raw.csv")
if err != nil {
log.Fatal(err)
}
reader := csv.NewReader(csvFile)
rows, err := reader.ReadAll()
if err != nil {
log.Fatal(err)
}
files, err := ioutil.ReadDir("data/init/audio")
if err != nil {
log.Fatal()
}
filtered := make([][]string, 0, len(rows))
LOOP:
for _, row := range rows[1:] {
csvPos := row[0]
csvWrd := row[1]
for _, file := range files {
fileWrd := strings.Split(file.Name(), ".")[1]
if fileWrd == csvWrd {
continue LOOP
}
}
filtered = append(filtered, []string{csvPos, csvWrd})
}
delay := 2 * time.Second
for _, row := range filtered {
pos := row[0]
wrd := row[1]
fmt.Println("pos:", pos)
fmt.Println("wrd:", wrd)
filename := fmt.Sprintf("data/init/audio/%s.%s.mp3", pos, wrd)
f, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
url := fmt.Sprintf("https://wooordhunt.ru/data/sound/word/us/mp3/%s.mp3", wrd)
r, err := http.DefaultClient.Get(url)
if err != nil {
log.Fatal(err)
}
_, err = io.Copy(f, r.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("sts: done\n\n")
time.Sleep(delay)
}
}