Returns path to audio files
This commit is contained in:
parent
d0ffc59bec
commit
e7d0bb9538
1 changed files with 9 additions and 4 deletions
13
main.go
13
main.go
|
@ -137,11 +137,13 @@ func speakWeather() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFile(path string) (s beep.StreamSeekCloser, format beep.Format, err error) {
|
func loadFile(filepath string) (name string, s beep.StreamSeekCloser, format beep.Format, err error) {
|
||||||
for _, decoder := range []func(io.ReadCloser) (beep.StreamSeekCloser, beep.Format, error){flac.Decode, mp3.Decode, wav.Decode} {
|
for _, decoder := range []func(io.ReadCloser) (beep.StreamSeekCloser, beep.Format, error){flac.Decode, mp3.Decode, wav.Decode} {
|
||||||
var fd *os.File
|
var fd *os.File
|
||||||
|
|
||||||
fd, err = os.Open(path)
|
name = path.Base(filepath)
|
||||||
|
|
||||||
|
fd, err = os.Open(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -183,17 +185,19 @@ func main() {
|
||||||
|
|
||||||
sampleRate := beep.SampleRate(*sr)
|
sampleRate := beep.SampleRate(*sr)
|
||||||
|
|
||||||
|
paths := []string{}
|
||||||
playlist := []beep.Streamer{}
|
playlist := []beep.Streamer{}
|
||||||
formats := []beep.Format{}
|
formats := []beep.Format{}
|
||||||
|
|
||||||
// Load playlist
|
// Load playlist
|
||||||
log.Println("Loading playlist...")
|
log.Println("Loading playlist...")
|
||||||
for _, arg := range flag.Args() {
|
for _, arg := range flag.Args() {
|
||||||
s, f, err := loadFile(arg)
|
p, s, f, err := loadFile(arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to load %s: %s", arg, err)
|
log.Printf("Unable to load %s: %s", arg, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
paths = append(paths, p)
|
||||||
playlist = append(playlist, s)
|
playlist = append(playlist, s)
|
||||||
formats = append(formats, f)
|
formats = append(formats, f)
|
||||||
}
|
}
|
||||||
|
@ -202,6 +206,7 @@ func main() {
|
||||||
log.Println("Shuffling playlist...")
|
log.Println("Shuffling playlist...")
|
||||||
// Shuffle the playlist
|
// Shuffle the playlist
|
||||||
rand.Shuffle(len(playlist), func(i, j int) {
|
rand.Shuffle(len(playlist), func(i, j int) {
|
||||||
|
paths[i], paths[j] = paths[j], paths[i]
|
||||||
playlist[i], playlist[j] = playlist[j], playlist[i]
|
playlist[i], playlist[j] = playlist[j], playlist[i]
|
||||||
formats[i], formats[j] = formats[j], formats[i]
|
formats[i], formats[j] = formats[j], formats[i]
|
||||||
})
|
})
|
||||||
|
@ -221,7 +226,7 @@ func main() {
|
||||||
if !hasClaironed && time.Since(launched) >= *claironTime {
|
if !hasClaironed && time.Since(launched) >= *claironTime {
|
||||||
log.Println("clairon time!")
|
log.Println("clairon time!")
|
||||||
hasClaironed = true
|
hasClaironed = true
|
||||||
sample, format, err := loadFile("/home/nemunaire/www/audio/miracle-morning/clairon-reveil.mp3")
|
_, sample, format, err := loadFile("/home/nemunaire/www/audio/miracle-morning/clairon-reveil.mp3")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
volume.Volume = 1
|
volume.Volume = 1
|
||||||
dontUpdateVolume = true
|
dontUpdateVolume = true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue