feat: 增加在线语音 SDK 和音色管理后台,完善引擎适配

This commit is contained in:
tongtong committed 2026-11-23 19:02:44 +08:00
1 parent 1856de97bc
commit a532ba4e0f
71 files changed
+3189 -472

No files matched your search

+30 -4
View File
@@ -26,6 +26,23 @@ func ShiftPitch(samples []float32, factor float32) []float32 {
}
func timeStretch(in []float32, factor float32) []float32 {
originalLength := len(in)
padded := make([]float32, len(in)+2*grain)
// Reflect boundaries so even sub-window sounds retain their energy.
for i := range padded {
at := i - grain
if len(in) == 1 {
padded[i] = in[0]
continue
}
period := 2 * (len(in) - 1)
at = ((at % period) + period) % period
if at >= len(in) {
at = period - at
}
padded[i] = in[at]
}
in = padded
hopA := roundInt(float32(hops) / factor)
if hopA < 1 {
hopA = 1
@@ -36,6 +53,7 @@ func timeStretch(in []float32, factor float32) []float32 {
expected = grain
}
out := make([]float32, expected+grain)
weights := make([]float32, len(out))
inPos, outPos := 0, 0
for inPos+grain <= len(in) {
@@ -49,7 +67,7 @@ func timeStretch(in []float32, factor float32) []float32 {
if to > len(in)-grain {
to = len(in) - grain
}
bestCorr := -1.0
bestCorr := 0.0
for cand := from; cand <= to; cand += 4 {
var corr float64
for i := 0; i < overlap; i++ {
@@ -63,13 +81,21 @@ func timeStretch(in []float32, factor float32) []float32 {
}
for i := 0; i < grain; i++ {
out[outPos+i] += in[best+i] * window[i]
weights[outPos+i] += window[i]
}
inPos += hopA
outPos += hops
}
result := make([]float32, expected)
copy(result, out[:min(expected, len(out))])
length := max(1, roundInt(float32(originalLength)*factor))
offset := roundInt(float32(grain) * factor)
result := make([]float32, length)
for i := range result {
at := offset + i
if at < len(out) && weights[at] > 0.00001 {
result[i] = out[at] / weights[at]
}
}
return result
}
@@ -106,4 +132,4 @@ func hann(size int) []float32 {
// roundInt matches Java Math.round(float): floor(x + 0.5).
func roundInt(x float32) int {
return int(math.Floor(float64(x) + 0.5))
}
}