feat: 增加在线语音 SDK 和音色管理后台,完善引擎适配
This commit is contained in:
1 parent
1856de97bc
commit
a532ba4e0f
71 files changed
+3189
-472
No files matched your search
@@ -53,4 +53,56 @@ func TestShiftPitchSilence(t *testing.T) {
|
||||
t.Fatalf("sample %d: got %v, want 0", i, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPitchShortAndTail(t *testing.T) {
|
||||
for _, length := range []int{100, 511, 1023, 1025, 2601} {
|
||||
for _, factor := range []float32{0.5, 1.2, 2} {
|
||||
in := make([]float32, length)
|
||||
for i := range in {
|
||||
in[i] = 0.5
|
||||
}
|
||||
out := ShiftPitch(in, factor)
|
||||
if math.Abs(float64(len(out)-length)) > 1 {
|
||||
t.Fatalf("length %d factor %v: %d", length, factor, len(out))
|
||||
}
|
||||
var energy float64
|
||||
for _, v := range out {
|
||||
energy += float64(v * v)
|
||||
}
|
||||
if energy < float64(length)*0.01 {
|
||||
t.Fatalf("short audio lost: length=%d factor=%v energy=%v", length, factor, energy)
|
||||
}
|
||||
var tail float64
|
||||
for _, v := range out[max(0, len(out)-100):] {
|
||||
tail += float64(v * v)
|
||||
}
|
||||
if tail < 0.01 {
|
||||
t.Fatalf("tail lost: length=%d factor=%v", length, factor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPitchChangesFrequency(t *testing.T) {
|
||||
const rate = 22050
|
||||
input := make([]float32, rate)
|
||||
for i := range input {
|
||||
input[i] = float32(0.5 * math.Sin(2*math.Pi*220*float64(i)/rate))
|
||||
}
|
||||
for _, factor := range []float32{0.5, 1.2, 2} {
|
||||
output := ShiftPitch(input, factor)
|
||||
from, to := rate/5, 4*rate/5
|
||||
crossings := 0
|
||||
for i := from + 1; i < to; i++ {
|
||||
if output[i-1] <= 0 && output[i] > 0 {
|
||||
crossings++
|
||||
}
|
||||
}
|
||||
frequency := float64(crossings) * rate / float64(to-from)
|
||||
want := 220 * float64(factor)
|
||||
if math.Abs(frequency/want-1) > 0.15 {
|
||||
t.Fatalf("pitch=%v frequency=%.1f want=%.1f", factor, frequency, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user