Add text-to-speech support. (#13)
Reviewed-on: #13 Co-authored-by: Anna Rose Wiggins <annabunches@gmail.com> Co-committed-by: Anna Rose Wiggins <annabunches@gmail.com>
This commit is contained in:
parent
3e4367f5e7
commit
9d262977f9
8 changed files with 203 additions and 32 deletions
|
|
@ -2,23 +2,22 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/holoplot/go-evdev"
|
||||
flag "github.com/spf13/pflag"
|
||||
|
||||
"git.annabunches.net/annabunches/joyful/internal/config"
|
||||
"git.annabunches.net/annabunches/joyful/internal/logger"
|
||||
"git.annabunches.net/annabunches/joyful/internal/mappingrules"
|
||||
"git.annabunches.net/annabunches/joyful/internal/virtualdevice"
|
||||
"github.com/holoplot/go-evdev"
|
||||
)
|
||||
|
||||
func getConfigDir() string {
|
||||
configFlag := flag.String("config", "~/.config/joyful", "Directory to read configuration from.")
|
||||
flag.Parse()
|
||||
configDir := strings.ReplaceAll(*configFlag, "~", "${HOME}")
|
||||
func getConfigDir(dir string) string {
|
||||
configDir := strings.ReplaceAll(dir, "~", "${HOME}")
|
||||
return os.ExpandEnv(configDir)
|
||||
}
|
||||
|
||||
|
|
@ -62,27 +61,46 @@ func initPhysicalDevices(config *config.ConfigParser) map[string]*evdev.InputDev
|
|||
}
|
||||
|
||||
func main() {
|
||||
// parse command-line
|
||||
var configFlag string
|
||||
flag.BoolVarP(&logger.IsDebugMode, "debug", "d", false, "Output very verbose debug messages.")
|
||||
flag.StringVarP(&configFlag, "config", "c", "~/.config/joyful", "Directory to read configuration from.")
|
||||
ttsOps := addTTSFlags()
|
||||
flag.Parse()
|
||||
|
||||
// parse configs
|
||||
configDir := getConfigDir()
|
||||
configDir := getConfigDir(configFlag)
|
||||
config := readConfig(configDir)
|
||||
|
||||
// initialize TTS
|
||||
tts, err := newTTS(ttsOps)
|
||||
logger.LogIfError(err, "Failed to initialize TTS")
|
||||
|
||||
// Initialize virtual devices with event buffers
|
||||
vBuffersByName, vBuffersByDevice := initVirtualBuffers(config)
|
||||
|
||||
// Initialize physical devices
|
||||
pDevices := initPhysicalDevices(config)
|
||||
|
||||
// Load the rules
|
||||
rules, eventChannel, cancel, wg := loadRules(config, pDevices, getVirtualDevices(vBuffersByName))
|
||||
|
||||
// initialize the mode variable
|
||||
mode := config.GetModes()[0]
|
||||
|
||||
// initialize TTS phrases for modes
|
||||
for _, m := range config.GetModes() {
|
||||
tts.AddMessage(m)
|
||||
logger.LogDebugf("Added TTS message '%s'", m)
|
||||
}
|
||||
|
||||
fmt.Println("Joyful Running! Press Ctrl+C to quit. Press Enter to reload rules.")
|
||||
if len(config.GetModes()) > 1 {
|
||||
logger.Logf("Initial mode set to '%s'", mode)
|
||||
}
|
||||
|
||||
for {
|
||||
lastMode := mode
|
||||
// Get an event (blocks if necessary)
|
||||
channelEvent := <-eventChannel
|
||||
|
||||
|
|
@ -124,6 +142,10 @@ func main() {
|
|||
rules, eventChannel, cancel, wg = loadRules(config, pDevices, getVirtualDevices(vBuffersByName))
|
||||
fmt.Println("Config re-loaded. Only rule changes applied. Device and Mode changes require restart.")
|
||||
}
|
||||
|
||||
if lastMode != mode && tts != nil {
|
||||
tts.Say(mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue