Skip to content

Commit

Permalink
created media.go file reorganized code
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Aug 24, 2021
1 parent dee3f07 commit c4a3480
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 154 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ func (b *Talkkonnect) ClientStart() {
}

if TTSEnabled && TTSTalkkonnectLoaded {
err := playWavLocal(TTSTalkkonnectLoadedFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSTalkkonnectLoadedFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: PlayWavLocal(TTSTalkkonnectLoadedFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSTalkkonnectLoadedFilenameAndPath) Returned Error: ", err)
}
}

Expand Down
20 changes: 10 additions & 10 deletions clientcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,23 +262,23 @@ func (b *Talkkonnect) ParticipantLEDUpdate(verbose bool) {

if EventSoundEnabled {
if participantCount > prevParticipantCount {
err := playWavLocal(EventJoinedSoundFilenameAndPath, 100)
err := aplayLocal(EventJoinedSoundFilenameAndPath, 100)
if err != nil {
log.Println("error: playWavLocal(EventJoinedSoundFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(EventJoinedSoundFilenameAndPath) Returned Error: ", err)
}
}
if participantCount < prevParticipantCount {
err := playWavLocal(EventLeftSoundFilenameAndPath, 100)
err := aplayLocal(EventLeftSoundFilenameAndPath, 100)
if err != nil {
log.Println("error: playWavLocal(EventLeftSoundFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(EventLeftSoundFilenameAndPath) Returned Error: ", err)
}
}
}

if participantCount > 1 && participantCount != prevParticipantCount {

if TTSEnabled && TTSParticipants {
b.Speak("There Are Currently "+strconv.Itoa(participantCount)+" Users in The Channel "+b.Client.Self.Channel.Name, "local")
b.Speak("There Are Currently "+strconv.Itoa(participantCount)+" Users in The Channel "+b.Client.Self.Channel.Name, "local", 1, 0, 1)
}

prevParticipantCount = participantCount
Expand Down Expand Up @@ -318,7 +318,7 @@ func (b *Talkkonnect) ParticipantLEDUpdate(verbose bool) {

if verbose {
if TTSEnabled && TTSParticipants {
b.Speak("You are Currently Alone in The Channel "+b.Client.Self.Channel.Name, "local")
b.Speak("You are Currently Alone in The Channel "+b.Client.Self.Channel.Name, "local", 1, 0, 1)
}
log.Println("info: Channel ", b.Client.Self.Channel.Name, " has no other participants")

Expand Down Expand Up @@ -404,9 +404,9 @@ func (b *Talkkonnect) ChannelUp() {
}

if TTSEnabled && TTSChannelUp {
err := playWavLocal(TTSChannelUpFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSChannelUpFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSChannelDownFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSChannelDownFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -475,9 +475,9 @@ func (b *Talkkonnect) ChannelDown() {
}

if TTSEnabled && TTSChannelDown {
err := playWavLocal(TTSChannelDownFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSChannelDownFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSChannelDownFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSChannelDownFilenameAndPath) Returned Error: ", err)
}

}
Expand Down
81 changes: 43 additions & 38 deletions commandkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func (b *Talkkonnect) cmdDisplayMenu() {
log.Println("debug: Delete Key Pressed Menu and Session Information Requested")

if TTSEnabled && TTSDisplayMenu {
err := playWavLocal(TTSDisplayMenuFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSDisplayMenuFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSDisplayMenuFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSDisplayMenuFilenameAndPath) Returned Error: ", err)
}

}
Expand All @@ -70,9 +70,9 @@ func (b *Talkkonnect) cmdMuteUnmute(subCommand string) {

log.Println("debug: F3 pressed Mute/Unmute Speaker Requested")
if TTSEnabled && TTSMuteUnMuteSpeaker {
err := playWavLocal(TTSMuteUnMuteSpeakerFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSMuteUnMuteSpeakerFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSMuteUnMuteSpeakerFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSMuteUnMuteSpeakerFilenameAndPath) Returned Error: ", err)
}
}

Expand Down Expand Up @@ -177,9 +177,9 @@ func (b *Talkkonnect) cmdCurrentVolume() {
log.Println("info: Volume Level is at", OrigVolume, "%")

if TTSEnabled && TTSCurrentVolumeLevel {
err := playWavLocal(TTSCurrentVolumeLevelFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSCurrentVolumeLevelFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSCurrentVolumeLevelFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSCurrentVolumeLevelFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -233,9 +233,9 @@ func (b *Talkkonnect) cmdVolumeUp() {
}

if TTSEnabled && TTSDigitalVolumeUp {
err := playWavLocal(TTSDigitalVolumeUpFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSDigitalVolumeUpFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSDigitalVolumeUpFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSDigitalVolumeUpFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -282,9 +282,9 @@ func (b *Talkkonnect) cmdVolumeDown() {
}

if TTSEnabled && TTSDigitalVolumeDown {
err := playWavLocal(TTSDigitalVolumeDownFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSDigitalVolumeDownFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSDigitalVolumeDownFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSDigitalVolumeDownFilenameAndPath) Returned Error: ", err)
}

}
Expand All @@ -295,9 +295,9 @@ func (b *Talkkonnect) cmdListServerChannels() {
log.Println("debug: F7 pressed Channel List Requested")

if TTSEnabled && TTSListServerChannels {
err := playWavLocal(TTSListServerChannelsFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSListServerChannelsFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSListServerChannelsFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSListServerChannelsFilenameAndPath) Returned Error: ", err)
}

}
Expand All @@ -311,9 +311,9 @@ func (b *Talkkonnect) cmdStartTransmitting() {
log.Println("info: Start Transmitting")

if TTSEnabled && TTSStartTransmitting {
err := playWavLocal(TTSStartTransmittingFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSStartTransmittingFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSStartTransmittingFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSStartTransmittingFilenameAndPath) Returned Error: ", err)
}

}
Expand All @@ -338,7 +338,7 @@ func (b *Talkkonnect) cmdStopTransmitting() {
log.Println("info: Stop Transmitting")

if TTSEnabled && TTSStopTransmitting {
err := playWavLocal(TTSStopTransmittingFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSStopTransmittingFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: Play Wav Local Module Returned Error: ", err)
}
Expand All @@ -365,9 +365,9 @@ func (b *Talkkonnect) cmdListOnlineUsers() {
log.Println("info: F10 Online User(s) in Current Channel")

if TTSEnabled && TTSListOnlineUsers {
err := playWavLocal(TTSListOnlineUsersFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSListOnlineUsersFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSListOnlineUsersFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSListOnlineUsersFilenameAndPath) Returned Error: ", err)
}

}
Expand All @@ -384,9 +384,9 @@ func (b *Talkkonnect) cmdPlayback() {
b.BackLightTimer()

if TTSEnabled && TTSPlayStream {
err := playWavLocal(TTSPlayStreamFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSPlayStreamFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSPlayStreamFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSPlayStreamFilenameAndPath) Returned Error: ", err)

}

Expand All @@ -413,9 +413,9 @@ func (b *Talkkonnect) cmdGPSPosition() {
log.Println("info: GPS details requested")

if TTSEnabled && TTSRequestGpsPosition {
err := playWavLocal(TTSRequestGpsPositionFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSRequestGpsPositionFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSRequestGpsPositionFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSRequestGpsPositionFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -449,9 +449,9 @@ func (b *Talkkonnect) cmdQuitTalkkonnect() {
log.Printf("info: Talkkonnect Now Running For %v \n", secondsToHuman(int(duration.Seconds())))

if TTSEnabled && TTSQuitTalkkonnect {
err := playWavLocal(TTSQuitTalkkonnectFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSQuitTalkkonnectFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSQuitTalkkonnectFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSQuitTalkkonnectFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -501,9 +501,9 @@ func (b *Talkkonnect) cmdSendEmail() {
}

if TTSEnabled && TTSSendEmail {
err := playWavLocal(TTSSendEmailFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSSendEmailFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("warn: playWavLocal(TTSSendEmailFilenameAndPath) Returned Error: ", err)
log.Println("warn: aplayLocal(TTSSendEmailFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -540,9 +540,9 @@ func (b *Talkkonnect) cmdConnPreviousServer() {
log.Println("info: Previous Server Requested")

if TTSEnabled && TTSPreviousServer {
err := playWavLocal(TTSPreviousServerFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSPreviousServerFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSPreviousServerFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSPreviousServerFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -582,9 +582,9 @@ func (b *Talkkonnect) cmdPingServers() {
log.Println("info: Ping Servers")

if TTSEnabled && TTSPingServers {
err := playWavLocal(TTSPingServersFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSPingServersFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("alert: playWavLocal(TTSPingServersFilenameAndPath) Returned Error: ", err)
log.Println("alert: aplayLocal(TTSPingServersFilenameAndPath) Returned Error: ", err)
}

}
Expand All @@ -597,9 +597,9 @@ func (b *Talkkonnect) cmdConnNextServer() {
log.Println("info: Next Server Requested Killing This Session, talkkonnect should be restarted by systemd")

if TTSEnabled && TTSNextServer {
err := playWavLocal(TTSNextServerFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSNextServerFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("alert: playWavLocal(TTSNextServerFilenameAndPath) Returned Error: ", err)
log.Println("alert: aplayLocal(TTSNextServerFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -721,9 +721,9 @@ func (b *Talkkonnect) cmdPanicSimulation() {
log.Println("info: Panic Button Start/Stop Simulation Requested")

if TTSEnabled && TTSPanicSimulation {
err := playWavLocal(TTSPanicSimulationFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSPanicSimulationFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSPanicSimulationFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSPanicSimulationFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -832,9 +832,9 @@ func (b *Talkkonnect) cmdScanChannels() {
log.Println("info: Scanning Channels")

if TTSEnabled && TTSScan {
err := playWavLocal(TTSScanFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSScanFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSScanFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSScanFilenameAndPath) Returned Error: ", err)
}

}
Expand Down Expand Up @@ -866,9 +866,9 @@ func (b *Talkkonnect) cmdDumpXMLConfig() {
log.Println("info: Print XML Config " + ConfigXMLFile)

if TTSEnabled && TTSPrintXmlConfig {
err := playWavLocal(TTSPrintXmlConfigFilenameAndPath, TTSVolumeLevel)
err := aplayLocal(TTSPrintXmlConfigFilenameAndPath, TTSVolumeLevel)
if err != nil {
log.Println("error: playWavLocal(TTSPrintXmlConfigFilenameAndPath) Returned Error: ", err)
log.Println("error: aplayLocal(TTSPrintXmlConfigFilenameAndPath) Returned Error: ", err)
}

}
Expand All @@ -881,5 +881,10 @@ func (b *Talkkonnect) cmdPlayRepeaterTone() {
log.Println("info: Play Repeater Tone on Speaker and Simulate RX Signal")

b.BackLightTimer()
b.RepeaterTone()
if RepeaterToneEnabled {
b.PlayTone(RepeaterToneFrequencyHz, RepeaterToneDurationSec, "local", true)
} else {
log.Println("warn: Repeater Tone Disabled by Config")
}

}
22 changes: 8 additions & 14 deletions htgotts.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ import (
"net/http"
"net/url"
"os"
"os/exec"
)

func (b *Talkkonnect) Speak(text string, destination string) {
func (b *Talkkonnect) Speak(text string, destination string, playBackVolume float32, duration float32, loop int) {
Folder := "audio"
generatedHashName := generateHashName(text)
fileName := Folder + "/" + generatedHashName + ".mp3"
fileNameWithPath := Folder + "/" + generatedHashName + ".mp3"

createFolderIfNotExists(Folder)
downloadIfNotExists(fileName, text)
downloadIfNotExists(fileNameWithPath, text)

if destination == "local" {
localmediaplayer(fileName)
localMediaPlayer(fileNameWithPath, playBackVolume, duration, loop)
}

if destination == "intostream" {
Expand All @@ -61,8 +60,8 @@ func (b *Talkkonnect) Speak(text string, destination string) {
IsPlayStream = true
NowStreaming = IsPlayStream

log.Println("info: Playing Recieved Text Message Into Stream as ", fileName)
b.playIntoStream(fileName, StreamSoundVolume)
log.Println("info: Playing Recieved Text Message Into Stream as ", fileNameWithPath)
b.playIntoStream(fileNameWithPath, StreamSoundVolume)
IsPlayStream = false
NowStreaming = IsPlayStream

Expand Down Expand Up @@ -106,24 +105,19 @@ func generateHashName(name string) string {
return hex.EncodeToString(hash[:])
}

func localmediaplayer(fileName string) {
localplayer := exec.Command("ffplay", "-autoexit", fileName)
localplayer.Run()
}

func (b *Talkkonnect) TTSPlayer(ttsMessage string, ttsLocalPlay bool, ttsLocalPlayRXLed bool, ttlPlayIntoStream bool) {

if ttsLocalPlay {
if ttsLocalPlayRXLed {
LEDOnFunc(VoiceActivityLED)
}
b.Speak(ttsMessage, "local")
b.Speak(ttsMessage, "local", 1, 0, 1)
if ttsLocalPlayRXLed {
LEDOffFunc(VoiceActivityLED)
}
}

if ttlPlayIntoStream {
b.Speak(ttsMessage, "intostream")
b.Speak(ttsMessage, "intostream", 1, 0, 1)
}
}
Loading

0 comments on commit c4a3480

Please sign in to comment.