Open adammfrank opened 5 years ago
I'm not in front of my computer but if I recall correctly, it doesn't seem that you are using the port audio API properly. Your buffer isn't 7s long and I believe port audio has some sort of callback mechanism when the buffer is ready to be dumped
Also you need to close the encoder to add the right headers to the file
did you manage to make them work together?
This code successfully saves a wav file, but the resulting file has weird clicking in the audio.
NOTE: s.Audio
is []int32
audioFile, err := os.Create(path.Join(dir, "audio.wav"))
if err != nil {
return err
}
defer audioFile.Close()
e := wav.NewEncoder(audioFile, sampleRate, 32, 1, 1)
defer e.Close()
buf := audio.IntBuffer{
Format: audio.FormatMono44100,
SourceBitDepth: 32,
}
for _, sample := range s.Audio {
buf.Data = append(buf.Data, int(sample))
}
err = e.Write(&buf)
if err != nil {
return err
}
The problem I was having was that I wasn't waiting until there was enough audio to fill the buffer, and that was causing samples to get recorded twice.
for avail := 0; avail < len(in); avail, _ = stream.AvailableToRead() {
time.Sleep(time.Second / sampleRate * time.Duration(len(in)-avail))
}
The only array type that portaudio and audio.IntBuffer both support is float32[]. When I run this code, nothing gets recorded. The file is silent. I don't know if this is the right place for this, but what the heck am I doing wrong? Is it something to do with converting to float32?