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"
"strings"
"time"
"flag"
"github.com/chzyer/readline"
"github.com/gopxl/beep"
@ -22,6 +23,10 @@ const (
)
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
soundMap := make(map[rune][]byte)
@ -75,10 +80,22 @@ func main() {
input := inputBuilder.String()
input = strings.ToLower(strings.TrimSpace(input))
for _, c := range input {
if c == '-' || c == '_' || c == ' ' || c == '\n' {
time.Sleep(longPause)
} else {
// Split the input into sections and process each section
sections := strings.FieldsFunc(input, func(r rune) bool {
return r == ' ' || r == '-' || r == '_'
})
fmt.Println("Playback starting...")
for _, section := range sections {
// Determine the number of times to read each section
numRepeats := 1
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 {
@ -86,7 +103,16 @@ func main() {
}
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

Loading…
Cancel
Save