mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-30 23:44:59 +00:00
wip(vad)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
59531562a6
commit
136fbd25f5
4 changed files with 86 additions and 19 deletions
|
@ -1,5 +1,7 @@
|
|||
package sound
|
||||
|
||||
import "math"
|
||||
|
||||
/*
|
||||
|
||||
MIT License
|
||||
|
@ -8,6 +10,17 @@ Copyright (c) 2024 Xbozon
|
|||
|
||||
*/
|
||||
|
||||
// calculateRMS16 calculates the root mean square of the audio buffer for int16 samples.
|
||||
func CalculateRMS16(buffer []int16) float64 {
|
||||
var sumSquares float64
|
||||
for _, sample := range buffer {
|
||||
val := float64(sample) // Convert int16 to float64 for calculation
|
||||
sumSquares += val * val
|
||||
}
|
||||
meanSquares := sumSquares / float64(len(buffer))
|
||||
return math.Sqrt(meanSquares)
|
||||
}
|
||||
|
||||
func ResampleInt16(input []int16, inputRate, outputRate int) []int16 {
|
||||
// Calculate the resampling ratio
|
||||
ratio := float64(inputRate) / float64(outputRate)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue