Skip to content
Snippets Groups Projects
Commit e2c711c4 authored by Malte Bauch's avatar Malte Bauch
Browse files

remove audio output

parent bffa7713
Branches
Tags
No related merge requests found
...@@ -23,13 +23,8 @@ type Application struct { ...@@ -23,13 +23,8 @@ type Application struct {
// Run runs the application. // Run runs the application.
func (a *Application) Run(controllerAddress string) { func (a *Application) Run(controllerAddress string) {
//init status map
statusMap = make(map[string]map[string]*InterfaceStatus) statusMap = make(map[string]map[string]*InterfaceStatus)
//load audio files
//initializeSoundFiles(soundFileOperStatusUP)
//initializeSoundFiles(soundFileOperStatusDOWN)
signal.Notify(a.stopChannel, os.Interrupt, syscall.SIGTERM) signal.Notify(a.stopChannel, os.Interrupt, syscall.SIGTERM)
a.eventServiceDevices.SubscribeToEventType([]event.TypeToCallbackTuple{ a.eventServiceDevices.SubscribeToEventType([]event.TypeToCallbackTuple{
...@@ -75,13 +70,7 @@ func (a *Application) DeviceCallback(event *event.Event) { ...@@ -75,13 +70,7 @@ func (a *Application) DeviceCallback(event *event.Event) {
if changedInterfaces != nil { if changedInterfaces != nil {
for _, changedInterface := range changedInterfaces { for _, changedInterface := range changedInterfaces {
playTTS(fmt.Sprintf("%s has changed the status to %s", changedInterface.Name, changedInterface.Status)) fmt.Printf("Change on %s: status of interface %s has changed to %s", changedInterface.NetworkElementName, changedInterface.Name, changedInterface.Status)
//if changedInterface.Status == "UP" {
// PlaySound(true)
//} else {
// PlaySound(false)
//}
fmt.Printf(`Change for device "%s" : Operational-State changed for interface "%s" to %s`, changedInterface.NetworkElementName, changedInterface.Name, changedInterface.Status)
} }
} }
} }
package main
import (
"log"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
htgotts "github.com/hegedustibor/htgo-tts"
"github.com/hegedustibor/htgo-tts/voices"
)
const (
soundFileOperStatusUP = "audio-files/up.mp3"
soundFileOperStatusDOWN = "audio-files/down.mp3"
)
var soundBuffers map[string]*beep.Buffer
func initializeSoundFiles(filename string) {
if soundBuffers == nil {
// init streamer
sampleRate := beep.SampleRate(48000)
speaker.Init(sampleRate, sampleRate.N(time.Second/10))
soundBuffers = make(map[string]*beep.Buffer)
}
f, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
streamer, format, err := mp3.Decode(f)
if err != nil {
log.Fatal(err)
}
buffer := beep.NewBuffer(format)
buffer.Append(streamer)
streamer.Close()
soundBuffers[filename] = buffer
}
func PlaySound(up bool) {
if up {
buffer := soundBuffers[soundFileOperStatusUP]
cableUP := buffer.Streamer(0, buffer.Len())
speaker.Play(cableUP)
} else {
buffer := soundBuffers[soundFileOperStatusDOWN]
cableUP := buffer.Streamer(0, buffer.Len())
speaker.Play(cableUP)
}
}
func playTTS(text string) {
speech := htgotts.Speech{Folder: "audio-files", Language: voices.German}
speech.Speak(text)
}
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
) )
func main() { func main() {
// TODO: add defer?
queueCredentials, err := registration.Register("localhost:55055", "ese-Application", "SecurePresharedToken") queueCredentials, err := registration.Register("localhost:55055", "ese-Application", "SecurePresharedToken")
if err != nil { if err != nil {
logrus.Errorf("failed to register application on control plane. %v", err) logrus.Errorf("failed to register application on control plane. %v", err)
......
...@@ -82,9 +82,7 @@ func checkIfOperationStateHasChanged(deviceServer device.DeviceServiceClient, ne ...@@ -82,9 +82,7 @@ func checkIfOperationStateHasChanged(deviceServer device.DeviceServiceClient, ne
return nil, nil return nil, nil
} }
statusList := walkThroughInterfaces(*&networkElement.Model.Interfaces.Interface, storedInterfaces) return walkThroughInterfaces(*&networkElement.Model.Interfaces.Interface, storedInterfaces)
return statusList, nil
} }
func addDeviceToStatusMap(networkElementName string, interfaces map[string]*arista.OpenconfigInterfaces_Interfaces_Interface) { func addDeviceToStatusMap(networkElementName string, interfaces map[string]*arista.OpenconfigInterfaces_Interfaces_Interface) {
...@@ -101,13 +99,13 @@ func addDeviceToStatusMap(networkElementName string, interfaces map[string]*aris ...@@ -101,13 +99,13 @@ func addDeviceToStatusMap(networkElementName string, interfaces map[string]*aris
statusMap[networkElementName] = statusList statusMap[networkElementName] = statusList
} }
func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_Interfaces_Interface, storedInterfaces map[string]*InterfaceStatus) []InterfaceStatus { func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_Interfaces_Interface, storedInterfaces map[string]*InterfaceStatus) ([]InterfaceStatus, error) {
statusList := make([]InterfaceStatus, 0) statusList := make([]InterfaceStatus, 0)
for _, receivedInterface := range interfaces { for _, receivedInterface := range interfaces {
storedInterface, ok := storedInterfaces[*receivedInterface.Name] storedInterface, ok := storedInterfaces[*receivedInterface.Name]
if !ok { if !ok {
//TODO: add error return statusList, fmt.Errorf("could not find %s in stored interfaces", *receivedInterface.Name)
} }
if storedInterface.Status != receivedInterface.State.OperStatus.String() { if storedInterface.Status != receivedInterface.State.OperStatus.String() {
...@@ -124,7 +122,7 @@ func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_In ...@@ -124,7 +122,7 @@ func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_In
go func() { go func() {
b, err := json.Marshal(statusMapCopy) b, err := json.Marshal(statusMapCopy)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println("error: ", err)
return return
} }
for clientChannel := range clientChannels { for clientChannel := range clientChannels {
...@@ -134,5 +132,5 @@ func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_In ...@@ -134,5 +132,5 @@ func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_In
} }
} }
return statusList return statusList, nil
} }
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
.changed { .changed {
outline:10px dashed transparent; outline:10px dashed transparent;
animation: changed 1s step-end 8; animation: changed 1s step-end 12;
} }
@keyframes changed { @keyframes changed {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment