Added -r flag to allow repeating sections like numbers stations typically do

pull/1/head
Aaron Johnon 1 year ago
parent ee2aa295f9
commit 32fe925b3c

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"time" "time"
"flag"
"github.com/chzyer/readline" "github.com/chzyer/readline"
"github.com/gopxl/beep" "github.com/gopxl/beep"
@ -22,6 +23,10 @@ const (
) )
func main() { func main() {
// Define and parse the -r flag
repeat := flag.Bool("r", false, "Repeat each section separated by space, '-', or '_'")
flag.Parse()
// Create a map to store sound data for each character // Create a map to store sound data for each character
soundMap := make(map[rune][]byte) soundMap := make(map[rune][]byte)
@ -75,18 +80,39 @@ func main() {
input := inputBuilder.String() input := inputBuilder.String()
input = strings.ToLower(strings.TrimSpace(input)) input = strings.ToLower(strings.TrimSpace(input))
for _, c := range input { // Split the input into sections and process each section
if c == '-' || c == '_' || c == ' ' || c == '\n' { sections := strings.FieldsFunc(input, func(r rune) bool {
time.Sleep(longPause) return r == ' ' || r == '-' || r == '_'
} else { })
if soundData, ok := soundMap[c]; ok {
playSound(soundData) fmt.Println("Playback starting...")
} else { for _, section := range sections {
fmt.Printf("Invalid character (skipping): %c\n", c) // Determine the number of times to read each section
} numRepeats := 1
time.Sleep(pauseBetweenCharacters) if *repeat {
numRepeats = 2
} }
// Read and optionally repeat each section
for i := 0; i < numRepeats; i++ {
for _, c := range section {
if soundData, ok := soundMap[c]; ok {
playSound(soundData)
} else {
fmt.Printf("Invalid character (skipping): %c\n", c)
}
time.Sleep(pauseBetweenCharacters)
}
// Pause between repeats if repeating
if *repeat && i == 0 {
time.Sleep(longPause)
}
}
// Long pause between sections
time.Sleep(longPause)
} }
fmt.Println("Playback finished. Exiting.")
} }
// Function to play sound // Function to play sound

Loading…
Cancel
Save