-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
func recordWav() string {
audioFileName := "temp.wav" //os.Args[1]
fmt.Println("Recording. Press ESC to quit.")
waveFile, err := os.Create(audioFileName)
chk(err)
// www.people.csail.mit.edu/hubert/pyaudio/ - under the Record tab
inputChannels := 1
outputChannels := 0
sampleRate := 44100
// init PortAudio
portaudio.Initialize()
//defer portaudio.Terminate()
encoder := wav.NewEncoder(waveFile, sampleRate, 16, 1, 1)
format := &audio.Format{
NumChannels: 1,
SampleRate: 44100,
}
data := make([]int, 4096)
buf := &audio.IntBuffer{Data: data, Format: format, SourceBitDepth: 16}
buf32 := buf.AsFloat32Buffer()
stream, err := portaudio.OpenDefaultStream(inputChannels, outputChannels, float64(sampleRate), 64, buf32.Data)
chk(err)
chk(stream.Start())
for start := time.Now(); time.Since(start) < time.Second*7; {
chk(stream.Read())
log.Println("Recording...")
// write to wave file
err := encoder.Write(buf)
chk(err)
}
stream.Close()
portaudio.Terminate()
return audioFileName
}
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?
Metadata
Metadata
Assignees
Labels
No labels