Add option to play wake up clairon

This commit is contained in:
nemunaire 2020-04-04 14:30:09 +02:00
parent 3119204f15
commit 0057ca3479
1 changed files with 17 additions and 0 deletions

17
main.go
View File

@ -160,6 +160,7 @@ func main() {
var weatherTime = flag.Duration("weather", -1, "Speak weather?")
var noshuffle = flag.Bool("noshuffle", false, "Don't shuffle music order")
var sr = flag.Int("samplerate", 44100, "Samplerate for unifying output stream")
var claironTime = flag.Duration("clairon", -1, "Time before running the wake up clairon song")
flag.DurationVar(&MaxRunTime, "maxruntime", MaxRunTime, "Maximum duration before auto exit")
flag.Parse()
@ -200,11 +201,27 @@ func main() {
var volume *effects.Volume
dontUpdateVolume := false
hasClaironed := claironTime == nil || *claironTime == -1
hasSpokeWeather := weatherTime == nil || *weatherTime == -1
// Create infinite stream
playedItem := -1
stream := beep.Iterate(func() beep.Streamer {
if !hasClaironed && time.Since(launched) >= *claironTime {
log.Println("clairon time!")
hasClaironed = true
sample, format, err := loadFile("/home/nemunaire/www/audio/miracle-morning/clairon-reveil.mp3")
if err == nil {
volume.Volume = 1
dontUpdateVolume = true
if format.SampleRate != sampleRate {
return beep.Resample(3, format.SampleRate, sampleRate, sample)
} else {
return sample
}
}
}
if !hasSpokeWeather && time.Since(launched) >= *weatherTime {
log.Println("weather time!")
hasSpokeWeather = true