forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_driver.go
76 lines (63 loc) · 1.76 KB
/
audio_driver.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Package audio is based on aplay audio adaptor written by @colemanserious (https://github.com/colemanserious)
package audio
import (
"time"
"gobot.io/x/gobot"
)
// Driver is gobot software device for audio playback
type Driver struct {
name string
connection gobot.Connection
interval time.Duration
halt chan bool
gobot.Eventer
gobot.Commander
filename string
}
// NewDriver returns a new audio Driver. It accepts:
//
// *Adaptor: The audio adaptor to use for the driver
// string: The filename of the audio to start playing
//
func NewDriver(a *Adaptor, filename string) *Driver {
return &Driver{
name: gobot.DefaultName("Audio"),
connection: a,
interval: 500 * time.Millisecond,
filename: filename,
halt: make(chan bool, 0),
Eventer: gobot.NewEventer(),
Commander: gobot.NewCommander(),
}
}
// Name returns the Driver Name
func (d *Driver) Name() string { return d.name }
// SetName sets the Driver Name
func (d *Driver) SetName(n string) { d.name = n }
// Filename returns the file name for the driver to playback
func (d *Driver) Filename() string { return d.filename }
// Connection returns the Driver Connection
func (d *Driver) Connection() gobot.Connection {
return d.connection
}
// Sound plays back a sound file. It accepts:
//
// string: The filename of the audio to start playing
func (d *Driver) Sound(fileName string) []error {
return d.Connection().(*Adaptor).Sound(fileName)
}
// Play plays back the current sound file.
func (d *Driver) Play() []error {
return d.Sound(d.Filename())
}
func (d *Driver) adaptor() *Adaptor {
return d.Connection().(*Adaptor)
}
// Start starts the Driver
func (d *Driver) Start() (err error) {
return
}
// Halt halts the Driver
func (d *Driver) Halt() (err error) {
return
}