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-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]) }
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]) }
// ReadAudioFile reads an audio file and converts it // into a sequence of MFCC vectors. func ReadAudioFile(file string) ([]linalg.Vector, error) { wavFile, err := wav.ReadSoundFile(file) if err != nil { return nil, err } var audioData []float64 for i, x := range wavFile.Samples() { if i%wavFile.Channels() == 0 { audioData = append(audioData, float64(x)) } } return SeqForAudioSamples(audioData, wavFile.SampleRate()), nil }
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 loadRawVoice(path string) (Voice, error) { // Read the directory f, err := os.Open(path) if err != nil { return nil, err } names, err := f.Readdirnames(-1) f.Close() if err != nil { return nil, err } // Load all WAV files res := Voice{} for _, name := range names { if !strings.HasSuffix(name, ".wav") { continue } baseName := name[0 : len(name)-4] sound, err := wav.ReadSoundFile(filepath.Join(path, name)) if err != nil { return nil, err } res[baseName] = sound } // Ensure that the voice has every edge phone. for _, phone := range AllPhones() { name := phone.Name() for _, entry := range []string{"-" + name, name + "-"} { if _, ok := res[entry]; !ok { return nil, errors.New("Missing edge phone: " + entry) } } } return res, nil }