func main() { if len(os.Args) < 4 { fmt.Fprintln(os.Stderr, "Usage: say-phones <output> <voice>", "<phones ...>") os.Exit(1) } phones := make([]gospeech.Phone, 0, len(os.Args)-3) for _, str := range os.Args[3:] { p, err := gospeech.ParsePhone(str) if err != nil { fmt.Fprintln(os.Stderr, "Invalid phone: "+str) os.Exit(1) } phones = append(phones, p) } voice, err := gospeech.LoadVoice(os.Args[2]) if err != nil { fmt.Fprintln(os.Stderr, "Failed to load voice:", err) os.Exit(1) } sound := gospeech.SynthesizePhones(phones, voice) if err := wav.WriteFile(sound, os.Args[1]); err != nil { fmt.Fprintln(os.Stderr, "Failed to write output:", err) os.Exit(1) } }
func ErrMain() error { if len(os.Args) != 4 { return errors.New("Usage: wav-volume <file.wav> <volume> <output.wav>") } s, err := wav.ReadSoundFile(os.Args[1]) if err != nil { return err } scale, err := strconv.ParseFloat(os.Args[2], 64) if err != nil { return err } wav.Volume(s, scale) return wav.WriteFile(s, os.Args[3]) }
func ErrMain() error { if len(os.Args) != 3 { return errors.New("Usage: wav-tone <frequency> <file.wav>") } freq, err := strconv.Atoi(os.Args[1]) if err != nil { return err } sampleRate := 44100 sound := wav.NewPCM8Sound(1, sampleRate) for i := 0; i < sampleRate*1; i++ { time := float64(i) / float64(sampleRate) value := wav.Sample(math.Sin(time * math.Pi * 2 * float64(freq))) sound.SetSamples(append(sound.Samples(), value)) } return wav.WriteFile(sound, os.Args[2]) }
func ErrMain() error { if len(os.Args) < 3 { return errors.New("Usage: wav-join <input.wav> [<another.wav> ...] " + "<output.wav>") } s, err := wav.ReadSoundFile(os.Args[1]) if err != nil { return err } for _, f := range os.Args[2 : len(os.Args)-1] { nextS, err := wav.ReadSoundFile(f) if err != nil { return err } wav.Append(s, nextS) } return wav.WriteFile(s, os.Args[len(os.Args)-1]) }
func ErrMain() error { if len(os.Args) != 5 { return errors.New("Usage: wav-gradient <file.wav> <start> <end> " + "<output.wav>") } s, err := wav.ReadSoundFile(os.Args[1]) if err != nil { return err } start, err := strconv.ParseFloat(os.Args[2], 64) if err != nil { return err } end, err := strconv.ParseFloat(os.Args[3], 64) if err != nil { return err } wav.Gradient(s, time.Duration(start*float64(time.Second)), time.Duration(end*float64(time.Second))) return wav.WriteFile(s, os.Args[4]) }
func ErrMain() error { if len(os.Args) != 5 { return errors.New("Usage: wav-overlay <input.wav> <overlay.wav> " + "<start> <output.wav>") } start, err := strconv.ParseFloat(os.Args[3], 64) if err != nil { return err } s1, err := wav.ReadSoundFile(os.Args[1]) if err != nil { return err } s2, err := wav.ReadSoundFile(os.Args[2]) if err != nil { return err } wav.Volume(s1, 0.5) wav.Volume(s2, 0.5) wav.Overlay(s1, s2, time.Duration(start*float64(time.Second))) return wav.WriteFile(s1, os.Args[4]) }