feat(chat): add Edge TTS playback
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
findSpeechSelectionStartOffset,
|
||||
splitSpeechTextIntoChunks,
|
||||
} from "./speechStartOptions";
|
||||
|
||||
describe("findSpeechSelectionStartOffset", () => {
|
||||
it("finds the reading start from selected reply text", () => {
|
||||
const text = "第一段内容。\n\n第二段 包含空格。\n第三段内容。";
|
||||
|
||||
expect(findSpeechSelectionStartOffset(text, "第二段 包含空格")).toBe(
|
||||
text.indexOf("第二段"),
|
||||
);
|
||||
expect(findSpeechSelectionStartOffset(text, "第三段")).toBe(text.indexOf("第三段"));
|
||||
expect(findSpeechSelectionStartOffset(text, "不存在")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("splitSpeechTextIntoChunks", () => {
|
||||
it("splits long text into bounded chunks", () => {
|
||||
const text = Array.from({ length: 80 }, (_, index) => `第${index}句内容足够长。`).join("");
|
||||
const chunks = splitSpeechTextIntoChunks(text);
|
||||
|
||||
expect(chunks.length).toBeGreaterThan(1);
|
||||
expect(chunks.every((chunk) => chunk.length <= 520)).toBe(true);
|
||||
expect(chunks.join("")).toBe(text);
|
||||
});
|
||||
|
||||
it("keeps short text as one chunk", () => {
|
||||
expect(splitSpeechTextIntoChunks("短句。")).toEqual(["短句。"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user