aboutsummaryrefslogtreecommitdiff
path: root/generate.sh
blob: 7c431ec676cec3e4c3652fe8818f3827787dc828 (plain) (blame)
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
#!/bin/sh
if [ $# != 1 ]; then
	echo >&2 "usage: $(basename "$0") <filename.wav>"
	exit 1
fi

filename="$1"
name="$(basename -s .wav "${filename}")"
root="$(dirname "$0")"

mkdir -p "${root}/cmd/${name}"
cp "${filename}" "${root}/cmd/${name}/${name}.wav"
gofmt > "${root}/cmd/${name}/${name}.go" << EOF
package main

import (
	"io/ioutil"
	"os"
	"os/exec"
)

//go:generate ../../generate.sh ${name}.wav
func main() {
	f, err := ioutil.TempFile(os.TempDir(), "${name}")
	if err != nil {
		panic(err)
	}
	defer os.Remove(f.Name())
	if _, err := f.Write(${name}); err != nil {
		panic(err)
	}
	cmd := exec.Command("afplay", f.Name())
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	if err := cmd.Run(); err != nil {
		panic(err)
	}
}

var ${name} = []byte{
	$(xxd -i < "${filename}" | sed 's/\([^,]\)$/\1,/')
}
EOF