Ejemplo n.º 1
0
// LoadVoice loads a voice from a directory.
func LoadVoice(path string) (Voice, error) {
	res, err := loadRawVoice(path)
	if err != nil {
		return nil, err
	}

	// Load the cuts.json file if possible
	f, err := os.Open(filepath.Join(path, "cuts.json"))
	if err != nil {
		return res, nil
	}
	defer f.Close()
	content, err := ioutil.ReadAll(f)
	if err != nil {
		return res, nil
	}

	// Parse cuts.json
	var cuts map[string]fileCut
	if err := json.Unmarshal(content, &cuts); err != nil {
		return res, nil
	}

	// Apply the cuts
	for name, cut := range cuts {
		if sound, ok := res[name]; ok {
			start := time.Duration(float64(time.Second) * cut.Start)
			end := time.Duration(float64(time.Second) * cut.End)
			wav.Crop(sound, start, end)
		}
	}

	return res, nil
}
Ejemplo n.º 2
0
Archivo: main.go Proyecto: delfvad/wav
func ErrMain() error {
	if len(os.Args) != 5 {
		return errors.New("Usage: wav-crop <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.Crop(s, time.Duration(start*float64(time.Second)),
		time.Duration(end*float64(time.Second)))
	return wav.WriteFile(s, os.Args[4])
}