Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(web): add bilingual speech service test audio

tianma-iff6aa3d738d8f
diff --git a/apps/web/src/components/settings/SpeechProviderCard.tsx b/apps/web/src/components/settings/SpeechProviderCard.tsx
index 6711fa4d..14409080 100644
--- a/apps/web/src/components/settings/SpeechProviderCard.tsx
+++ b/apps/web/src/components/settings/SpeechProviderCard.tsx
@@ -37,7 +37,7 @@ export const SpeechProviderCard = ({
readOnly: boolean;
onChanged: (settings: AiTranscriptionSettings) => void;
}) => {
- const { t } = useTranslation();
+ const { t, i18n } = useTranslation();
const [provider, setProvider] = useState<AiTranscriptionStandard>(saved.provider);
const [displayName, setDisplayName] = useState(saved.displayName);
const [baseUrl, setBaseUrl] = useState(saved.baseUrl);
@@ -83,7 +83,11 @@ export const SpeechProviderCard = ({
const key = apiKey.trim()
|| (await api.getAiTranscriptionDirectCredential(saved.id, controller.signal)).apiKey;
const { testSpeechService } = await import("@/lib/transcribe-note-resource");
- return await testSpeechService({ baseUrl, modelId: selectedModel.modelId, apiKey: key }, controller.signal);
+ return await testSpeechService(
+ { baseUrl, modelId: selectedModel.modelId, apiKey: key },
+ controller.signal,
+ { sampleLocale: i18n.resolvedLanguage ?? i18n.language },
+ );
} finally {
if (testAbortRef.current === controller) testAbortRef.current = null;
}
diff --git a/apps/web/src/components/settings/SpeechTranscriptionCard.tsx b/apps/web/src/components/settings/SpeechTranscriptionCard.tsx
index 03cd8d3a..811ede1a 100644
--- a/apps/web/src/components/settings/SpeechTranscriptionCard.tsx
+++ b/apps/web/src/components/settings/SpeechTranscriptionCard.tsx
@@ -35,7 +35,7 @@ const emptyDraft = {
};
export const SpeechTranscriptionCard = ({ demoMode }: { demoMode: boolean }) => {
- const { t } = useTranslation();
+ const { t, i18n } = useTranslation();
const queryClient = useQueryClient();
const settingsQuery = useQuery({
queryKey: ["ai-transcription-settings"],
@@ -83,7 +83,7 @@ export const SpeechTranscriptionCard = ({ demoMode }: { demoMode: boolean }) =>
baseUrl: draft.baseUrl,
modelId: draft.initialModelId,
apiKey: draft.apiKey.trim(),
- }, controller.signal);
+ }, controller.signal, { sampleLocale: i18n.resolvedLanguage ?? i18n.language });
} finally {
if (testAbortRef.current === controller) testAbortRef.current = null;
}
diff --git a/apps/web/src/lib/fixtures/speech-service-check.mp3 b/apps/web/src/lib/fixtures/speech-service-check.en-US.mp3
similarity index 100%
rename from apps/web/src/lib/fixtures/speech-service-check.mp3
rename to apps/web/src/lib/fixtures/speech-service-check.en-US.mp3
diff --git a/apps/web/src/lib/fixtures/speech-service-check.zh-CN.mp3 b/apps/web/src/lib/fixtures/speech-service-check.zh-CN.mp3
new file mode 100644
index 00000000..40caa341
Binary files /dev/null and b/apps/web/src/lib/fixtures/speech-service-check.zh-CN.mp3 differ
diff --git a/apps/web/src/lib/transcribe-note-resource.test.mjs b/apps/web/src/lib/transcribe-note-resource.test.mjs
index cb509d32..b8ae2948 100644
--- a/apps/web/src/lib/transcribe-note-resource.test.mjs
+++ b/apps/web/src/lib/transcribe-note-resource.test.mjs
@@ -52,8 +52,11 @@ describe("client-side note media preparation", () => {
input.dispose();
});
- test("bundles a real spoken MP3 for provider connection checks", async () => {
- const bytes = await readFile(fileURLToPath(new URL("./fixtures/speech-service-check.mp3", import.meta.url)));
+ test.each([
+ "speech-service-check.en-US.mp3",
+ "speech-service-check.zh-CN.mp3",
+ ])("bundles a real spoken MP3 for provider connection checks: %s", async (filename) => {
+ const bytes = await readFile(fileURLToPath(new URL(`./fixtures/${filename}`, import.meta.url)));
expect(bytes.byteLength).toBeGreaterThan(1_000);
const input = new Input({ formats: ALL_FORMATS, source: new BufferSource(bytes) });
expect(await input.canRead()).toBe(true);
@@ -61,8 +64,11 @@ describe("client-side note media preparation", () => {
input.dispose();
});
- test("connection check sends its sample from the client without saving settings", async () => {
- const bytes = await readFile(fileURLToPath(new URL("./fixtures/speech-service-check.mp3", import.meta.url)));
+ test.each([
+ ["default English", undefined, "speech-service-check.en-US.mp3"],
+ ["Chinese", "zh-CN", "speech-service-check.zh-CN.mp3"],
+ ])("connection check selects %s sample and sends it from the client", async (_label, sampleLocale, filename) => {
+ const bytes = await readFile(fileURLToPath(new URL(`./fixtures/${filename}`, import.meta.url)));
const requests = [];
const transcript = await testSpeechService(
{ baseUrl: "https://speech.example/v1/", modelId: "whisper-1", apiKey: "test-token" },
@@ -76,12 +82,15 @@ describe("client-side note media preparation", () => {
requests.push({ kind: "provider", url: String(url), init });
return Response.json({ text: "Hello, this is a speech recognition test." });
},
+ sampleLocale,
},
);
expect(transcript).toContain("speech recognition test");
expect(requests.map((request) => request.kind)).toEqual(["sample", "provider"]);
+ expect(requests[0].url).toEndWith(`/fixtures/${filename}`);
expect(requests[1].url).toBe("https://speech.example/v1/audio/transcriptions");
expect(requests[1].init.body.get("file")).toBeInstanceOf(File);
+ expect(requests[1].init.body.get("file").name).toBe(filename);
expect(requests[1].init.body.get("model")).toBe("whisper-1");
});
diff --git a/apps/web/src/lib/transcribe-note-resource.ts b/apps/web/src/lib/transcribe-note-resource.ts
index 0bc4f6c0..01246c20 100644
--- a/apps/web/src/lib/transcribe-note-resource.ts
+++ b/apps/web/src/lib/transcribe-note-resource.ts
@@ -214,16 +214,22 @@ export async function transcribePreparedAudioParts(
export async function testSpeechService(
target: { baseUrl: string; modelId: string; apiKey: string },
signal?: AbortSignal,
- transport: { sampleFetch?: typeof fetch; providerFetch?: typeof fetch } = {},
+ transport: { sampleFetch?: typeof fetch; providerFetch?: typeof fetch; sampleLocale?: string } = {},
): Promise<string> {
+ const sampleFilename = transport.sampleLocale?.toLowerCase().startsWith("zh")
+ ? "speech-service-check.zh-CN.mp3"
+ : "speech-service-check.en-US.mp3";
+ const sampleUrl = sampleFilename === "speech-service-check.zh-CN.mp3"
+ ? new URL("./fixtures/speech-service-check.zh-CN.mp3", import.meta.url)
+ : new URL("./fixtures/speech-service-check.en-US.mp3", import.meta.url);
const sampleResponse = await (transport.sampleFetch ?? fetch)(
- new URL("./fixtures/speech-service-check.mp3", import.meta.url),
+ sampleUrl,
{ signal },
);
if (!sampleResponse.ok) throw new Error("The built-in speech test audio is unavailable.");
const sample = new File(
[await sampleResponse.arrayBuffer()],
- "speech-service-check.mp3",
+ sampleFilename,
{ type: "audio/mpeg" },
);
async function* parts() { yield sample; }