gobot.io/x/gobot/v2@v2.1.0/platforms/audio/audio_driver.go (about) 1 // Package audio is based on aplay audio adaptor written by @colemanserious (https://github.com/colemanserious) 2 package audio 3 4 import ( 5 "time" 6 7 "gobot.io/x/gobot/v2" 8 ) 9 10 // Driver is gobot software device for audio playback 11 type Driver struct { 12 name string 13 connection gobot.Connection 14 interval time.Duration 15 halt chan bool 16 gobot.Eventer 17 gobot.Commander 18 filename string 19 } 20 21 // NewDriver returns a new audio Driver. It accepts: 22 // 23 // *Adaptor: The audio adaptor to use for the driver 24 // 25 // string: The filename of the audio to start playing 26 func NewDriver(a *Adaptor, filename string) *Driver { 27 return &Driver{ 28 name: gobot.DefaultName("Audio"), 29 connection: a, 30 interval: 500 * time.Millisecond, 31 filename: filename, 32 halt: make(chan bool), 33 Eventer: gobot.NewEventer(), 34 Commander: gobot.NewCommander(), 35 } 36 } 37 38 // Name returns the Driver Name 39 func (d *Driver) Name() string { return d.name } 40 41 // SetName sets the Driver Name 42 func (d *Driver) SetName(n string) { d.name = n } 43 44 // Filename returns the file name for the driver to playback 45 func (d *Driver) Filename() string { return d.filename } 46 47 // Connection returns the Driver Connection 48 func (d *Driver) Connection() gobot.Connection { 49 return d.connection 50 } 51 52 // Sound plays back a sound file. It accepts: 53 // 54 // string: The filename of the audio to start playing 55 func (d *Driver) Sound(fileName string) []error { 56 return d.Connection().(*Adaptor).Sound(fileName) 57 } 58 59 // Play plays back the current sound file. 60 func (d *Driver) Play() []error { 61 return d.Sound(d.Filename()) 62 } 63 64 func (d *Driver) adaptor() *Adaptor { 65 return d.Connection().(*Adaptor) 66 } 67 68 // Start starts the Driver 69 func (d *Driver) Start() (err error) { 70 return 71 } 72 73 // Halt halts the Driver 74 func (d *Driver) Halt() (err error) { 75 return 76 }