test: add qwen tts adapter and voice preference reproducers

This commit is contained in:
2026-07-23 22:21:52 +08:00
parent bf82ff9691
commit 39ff6f6ceb
2 changed files with 95 additions and 0 deletions
@@ -60,4 +60,44 @@ class AihrSpeechServiceTest {
assertThrows(IllegalArgumentException.class, () -> AihrSpeechService.buildRequestBody(
mapper, runtime, "测试", null, invalid));
}
@Test
void buildsDashScopeQwenTtsRequestAndNormalizesWorkspaceEndpoint() {
ObjectMapper mapper = new ObjectMapper();
SpeechModel runtime = new SpeechModel(
"dashscope",
"qwen-audio-3.0-tts-flash",
"",
""
);
var body = AihrSpeechService.buildDashScopeRequestBody(
mapper, runtime, "请先确认业主的诉求。",
new VoiceProfile("mentor", null, 0.88, "warm", "mandarin"));
assertEquals("qwen-audio-3.0-tts-flash", body.path("model").asText());
assertEquals("请先确认业主的诉求。", body.path("input").path("text").asText());
assertEquals("longanhuan_v3.6", body.path("input").path("voice").asText());
assertEquals("mp3", body.path("input").path("format").asText());
assertEquals(24000, body.path("input").path("sample_rate").asInt());
assertEquals(0.88, body.path("input").path("rate").asDouble());
assertEquals(
"https://ws-example.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer",
AihrSpeechService.dashScopeSynthesisUri("https://ws-example.cn-beijing.maas.aliyuncs.com/compatible-mode/v1").toString()
);
}
@Test
void extractsDashScopeAudioUrlOnlyWhenPresent() throws Exception {
ObjectMapper mapper = new ObjectMapper();
String response = """
{"output":{"audio":{"url":"http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/audio.mp3?sig=ok"}}}
""";
assertEquals(
"http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/audio.mp3?sig=ok",
AihrSpeechService.dashScopeAudioUrl(mapper, response).orElseThrow()
);
assertTrue(AihrSpeechService.dashScopeAudioUrl(mapper, "{\"output\":{}}").isEmpty());
}
}