Skip to content

Commit

Permalink
added tts messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Aug 21, 2021
1 parent fff57f4 commit cafdff3
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 6 deletions.
4 changes: 2 additions & 2 deletions clientcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (b *Talkkonnect) ParticipantLEDUpdate(verbose bool) {
if participantCount > 1 && participantCount != prevParticipantCount {

if TTSEnabled && TTSParticipants {
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")
}

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

if verbose {
if TTSEnabled && TTSParticipants {
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")
}
log.Println("info: Channel ", b.Client.Self.Channel.Name, " has no other participants")

Expand Down
71 changes: 70 additions & 1 deletion htgotts.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
/*
MIT License
Copyright (c) 2017 Tibor Hegedüs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Modified for talkkonnect by Suvir Kumar <[email protected]>
*/

package talkkonnect

import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
"os/exec"
)

func Speak(text string, destination string) {
func (b *Talkkonnect) Speak(text string, destination string) {
Folder := "audio"
generatedHashName := generateHashName(text)
fileName := Folder + "/" + generatedHashName + ".mp3"
Expand All @@ -23,6 +50,24 @@ func Speak(text string, destination string) {
localmediaplayer(fileName)
}

if destination == "intostream" {
b.BackLightTimer()

if b.IsTransmitting {
log.Println("alert: talkkonnect was already transmitting will now stop transmitting and start the stream")
b.TransmitStop(false)
}

IsPlayStream = true
NowStreaming = IsPlayStream

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

}

}

func createFolderIfNotExists(folder string) {
Expand Down Expand Up @@ -65,3 +110,27 @@ func localmediaplayer(fileName string) {
localplayer := exec.Command("ffplay", "-autoexit", fileName)
localplayer.Run()
}

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

// check if tts message read is enabled
if ttsMessageReadEnabled {
//check if the user wants local play
if ttsLocalPlay {
//check if the user wants local play with rxled on
if ttsLocalPlayRXLed {
LEDOnFunc(VoiceActivityLED)
}
b.Speak(ttsMessage, "local")
//check if the user wants local play with rxled on
if ttsLocalPlayRXLed {
LEDOffFunc(VoiceActivityLED)
}
}

//check if the user wants this message played into mumble stream
if ttlPlayIntoStream {
b.Speak(ttsMessage, "intostream")
}
}
}
6 changes: 5 additions & 1 deletion onevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func (b *Talkkonnect) OnTextMessage(e *gumble.TextMessageEvent) {

log.Println(fmt.Sprintf("info: Message ("+strconv.Itoa(len(message))+") from %v %v\n", sender, message))

voiceMessage := fmt.Sprintf("Message from %v %v\n", sender, cleanstring(e.Message))

b.TTSPlayer(voiceMessage, TTSMessageEnabled, TTSLocalPlay, TTSLocalPlayWithRXLED, TTSPlayIntoStream)

if TargetBoard == "rpi" {
if LCDEnabled {
LcdText[0] = "Msg From " + sender
Expand Down Expand Up @@ -234,7 +238,7 @@ func (b *Talkkonnect) OnUserChange(e *gumble.UserChangeEvent) {
if info != "" {
log.Println("info: User ", cleanstring(e.User.Name), " ", info, "Event type=", e.Type, " channel=", e.User.Channel.Name)
if TTSEnabled && TTSParticipants {
Speak("User "+cleanstring(e.User.Name)+info+"Has Changed to "+e.User.Channel.Name, "local")
b.Speak("User "+cleanstring(e.User.Name)+info+"Has Changed to "+e.User.Channel.Name, "local")
}
}

Expand Down
36 changes: 34 additions & 2 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (

//version and release date
const (
talkkonnectVersion string = "1.67.10"
talkkonnectVersion string = "1.67.11"
talkkonnectReleased string = "Aug 21 2021"
)

Expand Down Expand Up @@ -264,6 +264,7 @@ var (
PrintPanic bool
PrintAudioRecord bool
PrintMQTT bool
PrintTTSMessages bool
PrintKeyboardMap bool
PrintUSBKeyboard bool
)
Expand All @@ -289,6 +290,14 @@ var (
MQTTStore string
)

// ttsmessages settings
var (
TTSMessageEnabled bool
TTSLocalPlay bool
TTSLocalPlayWithRXLED bool
TTSPlayIntoStream bool
)

var (
Key0Enabled bool
Key0Targetid uint32
Expand Down Expand Up @@ -679,6 +688,7 @@ type DocumentStruct struct {
PrintPanic bool `xml:"printpanic"`
PrintAudioRecord bool `xml:"printaudiorecord"`
PrintMQTT bool `xml:"printmqtt"`
PrintTTSMessages bool `xml:"printttsmessages"`
PrintKeyboardMap bool `xml:"printkeyboardmap"`
PrintUSBKeyboard bool `xml:"printusbkeyboard"`
} `xml:"printvariables"`
Expand All @@ -696,6 +706,12 @@ type DocumentStruct struct {
MQTTAction string `xml:"action"`
MQTTStore string `xml:"store"`
} `xml:"mqtt"`
TTSMessages struct {
TTSMessageEnabled bool `xml:"enabled,attr"`
TTSLocalPlay bool `xml:"localplay"`
TTSLocalPlayWithRXLED bool `xml:"localplaywithrxled"`
TTSPlayIntoStream bool `xml:"playintostream"`
} `xml:"ttsmessages"`
} `xml:"software"`
Hardware struct {
TargetBoard string `xml:"targetboard,attr"`
Expand Down Expand Up @@ -1400,6 +1416,11 @@ func readxmlconfig(file string) error {
MQTTAction = Document.Global.Software.MQTT.MQTTAction
MQTTStore = Document.Global.Software.MQTT.MQTTStore

TTSMessageEnabled = Document.Global.Software.TTSMessages.TTSMessageEnabled
TTSLocalPlay = Document.Global.Software.TTSMessages.TTSLocalPlay
TTSLocalPlayWithRXLED = Document.Global.Software.TTSMessages.TTSLocalPlayWithRXLED
TTSPlayIntoStream = Document.Global.Software.TTSMessages.TTSPlayIntoStream

PrintHTTPAPI = Document.Global.Software.PrintVariables.PrintHTTPAPI
PrintTargetboard = Document.Global.Software.PrintVariables.PrintTargetBoard
PrintLeds = Document.Global.Software.PrintVariables.PrintLeds
Expand All @@ -1413,6 +1434,7 @@ func readxmlconfig(file string) error {
PrintPanic = Document.Global.Software.PrintVariables.PrintPanic
PrintAudioRecord = Document.Global.Software.PrintVariables.PrintAudioRecord
PrintMQTT = Document.Global.Software.PrintVariables.PrintMQTT
PrintTTSMessages = Document.Global.Software.PrintVariables.PrintTTSMessages
PrintKeyboardMap = Document.Global.Software.PrintVariables.PrintKeyboardMap
PrintUSBKeyboard = Document.Global.Software.PrintVariables.PrintUSBKeyboard
TargetBoard = Document.Global.Hardware.TargetBoard
Expand Down Expand Up @@ -1937,6 +1959,16 @@ func printxmlconfig() {
log.Println("info: ------------ MQTT Function ------- SKIPPED ")
}

if PrintTTSMessages {
log.Println("info: ------------ TTSMessages Function -------------- ")
log.Println("info: Enabled " + fmt.Sprintf("%v", TTSMessageEnabled))
log.Println("info: LocalPlay " + fmt.Sprintf("%v", TTSLocalPlay))
log.Println("info: LocalPlayWithRXLED " + fmt.Sprintf("%v", TTSLocalPlayWithRXLED))
log.Println("info: Play Into Stream " + fmt.Sprintf("%v", TTSPlayIntoStream))
} else {
log.Println("info: ------------ TTSMessages Function ------- SKIPPED ")
}

if PrintKeyboardMap {
log.Println("info: ------------ KeyboardMap Function -------------- ")
log.Printf("TTYKeymap %+v\n", TTYKeyMap)
Expand Down Expand Up @@ -1973,7 +2005,7 @@ func modifyXMLTagServerHopping(inputXMLFile string, newserverindex int) {

err := cmd.Run()
if err != nil {
log.Println("error: Failed to Set Next Server Tage with Error ", err)
log.Println("error: Failed to Set Next Server XML Tag with Error ", err)
}

time.Sleep(2 * time.Second)
Expand Down

0 comments on commit cafdff3

Please sign in to comment.