mirror of
https://github.com/mudler/LocalAI.git
synced 2025-01-28 15:13:56 +00:00
21 lines
356 B
Go
21 lines
356 B
Go
|
package sound
|
||
|
|
||
|
import (
|
||
|
"encoding/binary"
|
||
|
"math"
|
||
|
)
|
||
|
|
||
|
func BytesToFloat32Array(aBytes []byte) []float32 {
|
||
|
aArr := make([]float32, 3)
|
||
|
for i := 0; i < 3; i++ {
|
||
|
aArr[i] = BytesFloat32(aBytes[i*4:])
|
||
|
}
|
||
|
return aArr
|
||
|
}
|
||
|
|
||
|
func BytesFloat32(bytes []byte) float32 {
|
||
|
bits := binary.LittleEndian.Uint32(bytes)
|
||
|
float := math.Float32frombits(bits)
|
||
|
return float
|
||
|
}
|