]> git.giacomolli.uk - onechat/blob - voice_helper_test.go
Separate commands from the entry point
[onechat] / voice_helper_test.go
1 package main
2
3 import (
4 "os"
5 "os/exec"
6 "path/filepath"
7 "testing"
8
9 "github.com/stretchr/testify/require"
10 )
11
12 const voiceTestScript = `
13 while [ "$1" != --output-file ]; do shift; done
14 shift
15 printf 'A made-up voice transcript.\n' > "$1.txt"
16 `
17
18 func voiceTestInput(t *testing.T, script string) (*VoiceStore, *VoiceTranscriber) {
19 t.Helper()
20
21 dir := t.TempDir()
22 program := filepath.Join(dir, "whisper-cli")
23 shell, err := exec.LookPath("sh")
24 require.NoError(t, err)
25 require.NoError(t, os.WriteFile(program, []byte("#!"+shell+"\nset -eu\n"+script+"\n"), 0o700))
26
27 model := filepath.Join(dir, "model.bin")
28 require.NoError(t, os.WriteFile(model, []byte("made-up model"), 0o600))
29
30 return &VoiceStore{dir: filepath.Join(dir, voiceDirName)}, &VoiceTranscriber{config: VoiceConfig{
31 Transcriber: program,
32 Model: model,
33 }}
34 }