// https://github.com/gen2brain/malgo/blob/master/_examples/capture/capture.go
onRecvFrames := func(pSample2, pSample []byte, framecount uint32) {
// Empirically, len(pSample) is 480, so for sample rate 44100 it's triggered about every 10ms.
// sampleCount := framecount * deviceConfig.Capture.Channels * sizeInBytes
pSampleData = append(pSampleData, pSample...)
}
字符串 我可以将其转换为int(使用GPT-4):
func twoByteDataToIntSlice(audioData []byte) []int {
intData := make([]int, len(audioData)/2)
for i := 0; i < len(audioData); i += 2 {
// Convert the pCapturedSamples byte slice to int16 slice for FormatS16 as we go
value := int(binary.LittleEndian.Uint16(audioData[i : i+2]))
intData[i/2] = value
}
return intData
}
// Create an in-memory file to support io.WriteSeeker needed for NewEncoder which is needed for finalizing headers.
inMemoryFilename := "in-memory-output.wav"
inMemoryFile, err := fs.Create(inMemoryFilename)
dbg(err)
// We will call Close ourselves.
// Convert audio data to IntBuffer
inputBuffer := &audio.IntBuffer{Data: intData, Format: &audio.Format{SampleRate: iSampleRate, NumChannels: iNumChannels}}
// Create a new WAV wavEncoder
bitDepth := 16
audioFormat := 1
wavEncoder := wav.NewEncoder(inMemoryFile, iSampleRate, bitDepth, iNumChannels, audioFormat)
1条答案
按热度按时间lqfhib0f1#
最后我也用了
malgo
,用了malgo.FormatS16
。在此回调中生成字节的:
字符串
我可以将其转换为
int
(使用GPT-4):型
然后使用
"github.com/go-audio/wav"
来生成内存中的wav字节(GPT-4再次创建了内存中的FileSystem hack来克服io.WriteSeeker
的要求)型
我开发了这些片段,同时试图把你想要的东西放在一起-一个流媒体语音助手https://github.com/Petrzlen/vocode-golang