]> git.giacomolli.uk - onechat/blob - voice_helper_test.go
Transcribe stored voice notes locally
[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 func voiceTestInput(t *testing.T, script string) (*VoiceStore, *VoiceTranscriber) {
13 t.Helper()
14
15 dir := t.TempDir()
16 program := filepath.Join(dir, "whisper-cli")
17 shell, err := exec.LookPath("sh")
18 require.NoError(t, err)
19 require.NoError(t, os.WriteFile(program, []byte("#!"+shell+"\nset -eu\n"+script+"\n"), 0o700))
20
21 model := filepath.Join(dir, "model.bin")
22 require.NoError(t, os.WriteFile(model, []byte("made-up model"), 0o600))
23
24 return &VoiceStore{dir: filepath.Join(dir, voiceDirName)}, &VoiceTranscriber{config: VoiceConfig{
25 Transcriber: program,
26 Model: model,
27 }}
28 }