// SynthesizePhones uses the sounds in a voice to synthesize speech for a given // word. func SynthesizePhones(phones []Phone, v Voice) wav.Sound { res := wav.NewPCM8Sound(1, 44100) if len(phones) == 0 { return res } wav.Append(res, v["-"+phones[0].Name()]) for i := 0; i < len(phones)-1; i++ { wav.Append(res, getDiphone(phones[i], phones[i+1], v)) } wav.Append(res, v[phones[len(phones)-1].Name()+"-"]) return res }
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]) }