Skip to content

Commit b3f0921

Browse files
author
Talha Altinel
committed
gofumpt and note-type.apkg docs
1 parent 565afac commit b3f0921

8 files changed

Lines changed: 46 additions & 28 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.mp3
22
.idea/
3-
.code/
3+
.code/
4+
main

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ formatters:
103103
- gci
104104
- gofmt
105105
- goimports
106+
- gofumpt
106107
settings:
107108
gci:
108109
sections:

README.md

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@ the goddess of the thieves, helps you steal translation speeches from the G-dadd
1111

1212
<img src="https://github.com/user-attachments/assets/d1d344c9-f36b-4cf7-af70-f162f93ea9f0" width="400" alt="goddess-of-thieves">
1313

14+
## Installation
15+
16+
### Grab Binaries
17+
18+
You can find the binaries through GitHub [releases](https://github.com/mrwormhole/laverna/releases/).
19+
1420
### Install Via Go
1521

1622
```shell
1723
go install github.com/mrwormhole/laverna@latest
1824
```
1925

20-
### Grab Binaries
21-
22-
You can find binaries through GitHub releases.
26+
## Sample Usage
2327

24-
### Sample Usage
28+
### Basic
2529

2630
Let's create example CSV
2731

@@ -49,32 +53,48 @@ or you could do YAML
4953
Running below command will generate audios in the same directory.
5054
5155
```shell
52-
laverna -file example.csv
56+
laverna run -file example.csv
5357
```
5458

5559
or
5660

5761
```shell
58-
laverna -file example.yaml
62+
laverna run -file example.yaml
5963
```
6064

61-
### Shell Completions
65+
### Anki
6266

63-
Output shell completion script for bash, zsh, fish, or Powershell.
64-
Source the output to enable completion.
67+
Make sure you have note type installed for Anki. Here is the [note type](./note-type.apkg), when you imported it, you will see "Cloze Multi Choice Audio" note type in your `Anki > Tools > Manage Note Types`. Then you can proceed with the below Anki CSV format.
68+
69+
```csv
70+
Text,HelperText,TextA,TextB,TextC,TextD
71+
ฉันชอบ{{c1::ฟัง}}เพลง,I like to listen to music,ฟัง,เล่น,ดู,อ่าน
72+
```
73+
74+
```shell
75+
laverna anki --profile Talha --voice th --file ./testdata/anki-th-example.csv
76+
```
77+
78+
Now you will see a new result as below CSV file, all of your media is generated and inserted into Anki, however in order to create a deck in Anki, you need to import CSV below. And carefully choose comma delimiter with note type "Cloze Multi Choice Audio"
6579

66-
#### Bash
80+
```csv
81+
Text,HelperText,TextA,TextB,TextC,TextD,AudioA,AudioB,AudioC,AudioD,AudioAnswer
82+
ฉันชอบ{{c1::ฟัง}}เพลง,I like to listen to music,ฟัง,เล่น,ดู,อ่าน,[sound:a.mp3],[sound:b.mp3],[sound:c.mp3],[sound:d.mp3],[sound:e.mp3]
83+
```
84+
85+
![anki-front-card](https://github.com/user-attachments/assets/fbc19bd1-0d74-4659-b9a0-2e40e9e8d4cf)
6786

68-
source <(laverna completion bash)
87+
![anki-back-card](https://github.com/user-attachments/assets/6cca4cfc-237a-493f-8306-0972278231fa)
6988

70-
#### Zsh
89+
## Shell Completions
7190

72-
source <(laverna completion zsh)
91+
Output shell completion script for bash, zsh, fish, or Powershell.
92+
Source the output to enable completion.
7393

74-
#### Fish
94+
### Bash / Zsh
7595

76-
laverna completion fish > ~/.config/fish/completions/laverna.fish
96+
```source <(laverna completion bash)``` or ```source <(laverna completion zsh)```
7797

78-
#### Powershell
98+
### Fish
7999

80-
Output the script to path/to/autocomplete/laverna.ps1 an run it.
100+
```laverna completion fish > ~/.config/fish/completions/laverna.fish```

anki/runner.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func NewRunner(profile string, opts ...RunnerOption) (*Runner, error) {
8080
fp := filepath.Join(path, filename)
8181

8282
// ensure directory exists
83-
if err := os.MkdirAll(path, 0750); err != nil {
83+
if err := os.MkdirAll(path, 0o750); err != nil {
8484
return fmt.Errorf("failed to make directory(%q): %w", path, err)
8585
}
8686

@@ -92,7 +92,7 @@ func NewRunner(profile string, opts ...RunnerOption) (*Runner, error) {
9292
return fmt.Errorf("failed to check file(%q): %w", fp, err)
9393
}
9494

95-
return os.WriteFile(fp, audio, 0600)
95+
return os.WriteFile(fp, audio, 0o600)
9696
}
9797
r.save = saveFile
9898

@@ -239,9 +239,7 @@ func (r *Runner) Run(ctx context.Context, reader io.Reader, c RunConfig) error {
239239
if err != nil {
240240
return fmt.Errorf("os.Create(%q): %w", c.OutFilename, err)
241241
}
242-
defer func() {
243-
_ = outFile.Close()
244-
}()
242+
defer func() { _ = outFile.Close() }()
245243

246244
if err := WriteCSVRecords(outFile, records, c.StripCSVHeader, c.Shuffle); err != nil {
247245
return fmt.Errorf("WriteCSVRecords(%q): %w", outFile.Name(), err)

commands.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ func ankiCmd(ctx context.Context, filename string, maxWorkers int, profile strin
5555
if err != nil {
5656
return fmt.Errorf("failed to open file(%q): %v", filename, err)
5757
}
58-
defer func() {
59-
_ = f.Close()
60-
}()
58+
defer func() { _ = f.Close() }()
6159

6260
runner, err := anki.NewRunner(profile, anki.WithMaxWorkers(maxWorkers))
6361
if err != nil {

note-type.apkg

99.7 KB
Binary file not shown.

synthesize/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewRunner(opts ...RunnerOption) *Runner {
2626
client: http.DefaultClient,
2727
maxWorkers: runtime.GOMAXPROCS(0),
2828
save: func(filename string, audio []byte) error {
29-
return os.WriteFile(filename+".mp3", audio, 0600)
29+
return os.WriteFile(filename+".mp3", audio, 0o600)
3030
},
3131
}
3232

synthesize/runner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestBatchRunner(t *testing.T) {
3232
{Text: "test2", Voice: EnglishVoice},
3333
},
3434
saveFn: func(text string, audio []byte) error {
35-
return os.WriteFile(filepath.Join(temp, text+".mp3"), audio, 0600)
35+
return os.WriteFile(filepath.Join(temp, text+".mp3"), audio, 0o600)
3636
},
3737
wantAudios: []string{
3838
filepath.Join(temp, "test1.mp3"),

0 commit comments

Comments
 (0)