/
enumerate.go
57 lines (48 loc) · 1.48 KB
/
enumerate.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
package cmd
import (
"fmt"
"os"
"text/template"
"github.com/gordonklaus/portaudio"
"github.com/spf13/cobra"
)
var enumerateCmd = &cobra.Command{
Use: "enumerate",
Short: "List all available audio devices and supported Host APIs",
Long: `List all available audio devices and supported Host APIs`,
Run: func(cmd *cobra.Command, args []string) {
enumerate()
},
}
func init() {
RootCmd.AddCommand(enumerateCmd)
}
var tmpl = template.Must(template.New("").Parse(
`
Available audio devices and supported Host APIs:
Detected {{. | len}} host API(s): {{range .}}
Name: {{.Name}}
{{if .DefaultInputDevice}}Default input device: {{.DefaultInputDevice.Name}}{{end}}
{{if .DefaultOutputDevice}}Default output device: {{.DefaultOutputDevice.Name}}{{end}}
Devices: {{range .Devices}}
Name: {{.Name}}
MaxInputChannels: {{.MaxInputChannels}}
MaxOutputChannels: {{.MaxOutputChannels}}
DefaultLowInputLatency: {{.DefaultLowInputLatency}}
DefaultLowOutputLatency: {{.DefaultLowOutputLatency}}
DefaultHighInputLatency: {{.DefaultHighInputLatency}}
DefaultHighOutputLatency: {{.DefaultHighOutputLatency}}
DefaultSampleRate: {{.DefaultSampleRate}}
{{end}}
{{end}}`,
))
// enumerate lists all available Audio devices on the system
func enumerate() {
portaudio.Initialize()
defer portaudio.Terminate()
hs, err := portaudio.HostApis()
if err != nil {
fmt.Println(err)
}
err = tmpl.Execute(os.Stdout, hs)
}