@sonicloud/dsh-sonicloud-device 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/CHANGELOG.zh.md +29 -0
- package/LICENSE +25 -0
- package/README.md +134 -2
- package/cordis.patch.yml +3 -0
- package/dist/build.json +5 -0
- package/dist/client.js +20621 -0
- package/docs/contributing/development.md +200 -0
- package/docs/specs/ci-cd.md +126 -0
- package/docs/specs/mouse-settings.md +255 -0
- package/docs/specs/smart-mouse-plugin.md +239 -0
- package/native/COPYING.LGPLv2.1 +502 -0
- package/native/LICENSE.hidapi-bsd +26 -0
- package/native/README.md +15 -0
- package/native/SOURCE.json +16 -0
- package/native/THIRD_PARTY_LICENSES.txt +69 -0
- package/native/darwin-arm64/README.md +71 -0
- package/native/darwin-arm64/libavcodec.62.28.102.dylib +0 -0
- package/native/darwin-arm64/libavcodec.62.dylib +0 -0
- package/native/darwin-arm64/libavutil.60.26.102.dylib +0 -0
- package/native/darwin-arm64/libavutil.60.dylib +0 -0
- package/native/darwin-arm64/libuMouseSdk.0.4.20.dylib +0 -0
- package/native/darwin-arm64/libuMouseSdk.0.dylib +0 -0
- package/native/darwin-arm64/libuMouseSdk.dylib +0 -0
- package/native/desktop/CompatibilityPolicy.swift +17 -0
- package/native/desktop/VoicePanel.cs +197 -0
- package/native/desktop/VoicePanel.swift +322 -0
- package/native/desktop/darwin-arm64/Sonicloud Voice.app/Contents/Info.plist +10 -0
- package/native/desktop/darwin-arm64/Sonicloud Voice.app/Contents/MacOS/sonicloud-voice +0 -0
- package/native/desktop/windows.ps1 +9 -0
- package/native/win32-x64/README.md +70 -0
- package/native/win32-x64/avcodec-58.dll +0 -0
- package/native/win32-x64/avutil-56.dll +0 -0
- package/native/win32-x64/msvcp140.dll +0 -0
- package/native/win32-x64/uMouseSdk.dll +0 -0
- package/native/win32-x64/vcruntime140.dll +0 -0
- package/native/win32-x64/vcruntime140_1.dll +0 -0
- package/package.json +74 -4
- package/src/asr/auth.mjs +80 -0
- package/src/asr/config.mjs +6 -0
- package/src/asr/languages.mjs +28 -0
- package/src/asr/stream.mjs +149 -0
- package/src/client/assets/contact-wechat.jpg +0 -0
- package/src/client/assets/sonicloud.png +0 -0
- package/src/client/assets/sonicloud.svg +3 -0
- package/src/desktop/presentation.mjs +87 -0
- package/src/devices/actions.mjs +46 -0
- package/src/devices/config.mjs +9 -0
- package/src/devices/diagnostics.mjs +52 -0
- package/src/devices/manager.mjs +335 -0
- package/src/devices/native-worker.mjs +64 -0
- package/src/devices/native.mjs +86 -0
- package/src/devices/queue.mjs +32 -0
- package/src/devices/recognition.mjs +23 -0
- package/src/devices/store.mjs +44 -0
- package/src/devices/translate.mjs +44 -0
- package/src/host/ai-conversation.mjs +83 -0
- package/src/host/index.mjs +96 -0
- package/src/host/store.mjs +24 -0
- package/src/shared/devices.mjs +69 -0
- package/src/shared/languages.mjs +111 -0
- package/src/shared/mouse-settings.mjs +22 -0
- package/src/shared/remote.mjs +55 -0
- package/src/shared/transcript.mjs +16 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { AsyncQueue } from '../devices/queue.mjs';
|
|
3
|
+
|
|
4
|
+
// A voice session belongs to one client connection; never retry insertion in another window.
|
|
5
|
+
export class AiConversationBridge {
|
|
6
|
+
constructor({ timeoutMs = 10000 } = {}) {
|
|
7
|
+
this.timeoutMs = timeoutMs;
|
|
8
|
+
this.clients = new Set(); this.sessions = new Map(); this.requests = new Map();
|
|
9
|
+
}
|
|
10
|
+
async *watch(clientId, signal) {
|
|
11
|
+
if (this.closed) return;
|
|
12
|
+
const client = { clientId, queue: new AsyncQueue(64) };
|
|
13
|
+
const abort = () => client.queue.end(true);
|
|
14
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
15
|
+
try {
|
|
16
|
+
signal.throwIfAborted(); this.clients.add(client);
|
|
17
|
+
for (const pending of this.requests.values()) this.dispatch(pending);
|
|
18
|
+
yield* client.queue;
|
|
19
|
+
} finally {
|
|
20
|
+
signal.removeEventListener('abort', abort); this.clients.delete(client); client.queue.end(true);
|
|
21
|
+
for (const [id, session] of this.sessions) {
|
|
22
|
+
if (session.client === client) this.release(id, 'AI 对话连接已断开,结果可复制');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
dispatch(pending) {
|
|
27
|
+
if (pending.sent) return;
|
|
28
|
+
const session = this.sessions.get(pending.message.sessionId);
|
|
29
|
+
if (!session) return;
|
|
30
|
+
session.client ??= this.clients.values().next().value;
|
|
31
|
+
if (!session.client) return;
|
|
32
|
+
pending.sent = true;
|
|
33
|
+
try { session.client.queue.push(pending.message); }
|
|
34
|
+
catch { pending.reject(new Error('AI 对话连接繁忙,请重试')); }
|
|
35
|
+
}
|
|
36
|
+
request(sessionId, operation, signal, text, autoSend) {
|
|
37
|
+
signal.throwIfAborted();
|
|
38
|
+
if (this.closed || !this.sessions.has(sessionId)) return Promise.reject(new Error('AI 对话连接不可用'));
|
|
39
|
+
const requestId = randomUUID();
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const cleanup = () => { clearTimeout(timer); signal.removeEventListener('abort', abort); this.requests.delete(requestId); };
|
|
42
|
+
const fail = error => { cleanup(); reject(error); };
|
|
43
|
+
const abort = () => fail(new Error('AI 语音会话已取消'));
|
|
44
|
+
const timer = setTimeout(() => {
|
|
45
|
+
fail(new Error('AI 对话未响应,结果可复制'));
|
|
46
|
+
this.release(sessionId);
|
|
47
|
+
}, this.timeoutMs);
|
|
48
|
+
const pending = { message: { requestId, sessionId, operation, expiresAt: Date.now() + this.timeoutMs, ...(text === undefined ? {} : { text, autoSend }) },
|
|
49
|
+
resolve: () => { cleanup(); resolve(true); }, reject: fail };
|
|
50
|
+
this.requests.set(requestId, pending);
|
|
51
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
52
|
+
this.dispatch(pending);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
prepare(run) {
|
|
56
|
+
this.sessions.set(run.id, {});
|
|
57
|
+
return this.request(run.id, 'prepare', run.lifetime.signal);
|
|
58
|
+
}
|
|
59
|
+
insert(run, text) { return this.request(run.id, 'insert', run.lifetime.signal, text, run.preferences?.aiAutoSend ?? true); }
|
|
60
|
+
answer(clientId, requestId, ok) {
|
|
61
|
+
const pending = this.requests.get(requestId);
|
|
62
|
+
const session = pending && this.sessions.get(pending.message.sessionId);
|
|
63
|
+
if (!pending?.sent || session?.client?.clientId !== clientId) return false;
|
|
64
|
+
if (ok) pending.resolve();
|
|
65
|
+
else pending.reject(new Error('AI 对话无法创建、填充或自动发送,结果可复制'));
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
release(sessionId, message = 'AI 语音会话已结束') {
|
|
69
|
+
const session = this.sessions.get(sessionId);
|
|
70
|
+
this.sessions.delete(sessionId);
|
|
71
|
+
for (const pending of this.requests.values()) {
|
|
72
|
+
if (pending.message.sessionId === sessionId) pending.reject(new Error(message));
|
|
73
|
+
}
|
|
74
|
+
try { session?.client?.queue.push({ requestId: randomUUID(), sessionId, operation: 'release' }); }
|
|
75
|
+
catch { session?.client?.queue.end(true); }
|
|
76
|
+
}
|
|
77
|
+
close() {
|
|
78
|
+
this.closed = true;
|
|
79
|
+
for (const id of this.sessions.keys()) this.release(id);
|
|
80
|
+
for (const client of this.clients) client.queue.end();
|
|
81
|
+
this.clients.clear();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
2
|
+
import { ServiceStore } from './store.mjs';
|
|
3
|
+
import { createTokenProvider } from '../asr/auth.mjs';
|
|
4
|
+
import { streamRecognition } from '../asr/stream.mjs';
|
|
5
|
+
import { translateText } from '../devices/translate.mjs';
|
|
6
|
+
import { TYPERT } from '../shared/remote.mjs';
|
|
7
|
+
import { DeviceManager } from '../devices/manager.mjs';
|
|
8
|
+
import { MouseSdk } from '../devices/native.mjs';
|
|
9
|
+
import { DesktopPresentation } from '../desktop/presentation.mjs';
|
|
10
|
+
import { pluginConfigSchema } from '../devices/config.mjs';
|
|
11
|
+
import { AiConversationBridge } from './ai-conversation.mjs';
|
|
12
|
+
|
|
13
|
+
export const name = 'dsh-sonicloud-device';
|
|
14
|
+
export const inject = ['credentials', 'typert'];
|
|
15
|
+
export class MouseController extends TypertRemoteService {
|
|
16
|
+
constructor(ctx, config = {}, dependencies = {}) {
|
|
17
|
+
super(ctx, 'sinicloudAsr', { namespace: 'asr' });
|
|
18
|
+
config = pluginConfigSchema.parse(config);
|
|
19
|
+
this.store = new ServiceStore(ctx.credentials);
|
|
20
|
+
this.dependencies = dependencies;
|
|
21
|
+
this.providers = new Map(); this.lifetime = new AbortController();
|
|
22
|
+
// 即使没有设备连接,也完成遗留凭据清理;失败时禁止发起业务请求。
|
|
23
|
+
this.initialized = this.store.state();
|
|
24
|
+
this.initialized.catch(() => {});
|
|
25
|
+
this.aiConversation = dependencies.aiConversation ?? new AiConversationBridge();
|
|
26
|
+
this.manager = new DeviceManager({ credentials: ctx.credentials, config,
|
|
27
|
+
sdk: dependencies.sdk ?? new MouseSdk(config.native), ...dependencies, aiConversation: this.aiConversation,
|
|
28
|
+
prepare: () => this.service(), recognize: request => this.recognize(request),
|
|
29
|
+
translate: request => this.translate(request) });
|
|
30
|
+
ctx.effect(() => () => {
|
|
31
|
+
this.lifetime.abort(); this.providers.clear(); return this.manager.close();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async service() { await this.initialized; return { ...await this.store.resolve(), ...this.dependencies.endpoints }; }
|
|
35
|
+
catalog() { return this.store.catalog(); }
|
|
36
|
+
devices() { return this.manager.view(); }
|
|
37
|
+
saveDevice(sn, revision, preferences) { return this.manager.save(sn, revision, preferences); }
|
|
38
|
+
watch(clientId, signal) { return this.manager.watch(clientId, signal); }
|
|
39
|
+
accept(clientId, sessionId) { return this.manager.accept(clientId, sessionId); }
|
|
40
|
+
watchAi(clientId, signal) { return this.aiConversation.watch(clientId, signal); }
|
|
41
|
+
answerAi(clientId, requestId, ok) { return this.aiConversation.answer(clientId, requestId, ok); }
|
|
42
|
+
cancel(clientId, sessionId) { this.manager.assertOwner(clientId); this.manager.cancel(sessionId); return true; }
|
|
43
|
+
provider(sn, service) {
|
|
44
|
+
const key = JSON.stringify([service.tokenUrl, sn]);
|
|
45
|
+
if (!this.providers.has(key)) this.providers.set(key,
|
|
46
|
+
createTokenProvider({ tokenUrl: service.tokenUrl, sn }, this.dependencies.fetchImpl ?? globalThis.fetch, this.lifetime.signal));
|
|
47
|
+
return this.providers.get(key);
|
|
48
|
+
}
|
|
49
|
+
async *recognize({ sn, query, uplink, signal, service: capturedService }) {
|
|
50
|
+
const connection = new AbortController();
|
|
51
|
+
const timeout = this.dependencies.connectTimeout ?? 10_000;
|
|
52
|
+
const timer = setTimeout(() => connection.abort(), timeout);
|
|
53
|
+
const combined = AbortSignal.any([signal, this.lifetime.signal, connection.signal]);
|
|
54
|
+
const deadline = Date.now() + timeout;
|
|
55
|
+
try {
|
|
56
|
+
const service = capturedService ?? await this.service();
|
|
57
|
+
combined.throwIfAborted();
|
|
58
|
+
const getToken = this.provider(sn, service);
|
|
59
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
60
|
+
const token = await getToken(combined);
|
|
61
|
+
combined.throwIfAborted();
|
|
62
|
+
let retry = false;
|
|
63
|
+
for await (const event of streamRecognition({
|
|
64
|
+
service: { ...service, recognitionQuery: query }, token, uplink, signal: combined,
|
|
65
|
+
WebSocketImpl: this.dependencies.WebSocketImpl,
|
|
66
|
+
connectTimeout: Math.max(1, deadline - Date.now()),
|
|
67
|
+
onAuthFailure: () => getToken.invalidate(token),
|
|
68
|
+
})) {
|
|
69
|
+
if (event.type === 'ready') clearTimeout(timer);
|
|
70
|
+
if (event.type === 'error' && event.code === '4010' && event.retryable && attempt === 0) { retry = true; break; }
|
|
71
|
+
yield event;
|
|
72
|
+
if (event.type === 'error') return;
|
|
73
|
+
}
|
|
74
|
+
combined.throwIfAborted();
|
|
75
|
+
if (!retry) return;
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (!signal.aborted && !this.lifetime.signal.aborted) yield { type: 'error',
|
|
79
|
+
message: connection.signal.aborted ? 'ASR 连接超时,请稍后重试'
|
|
80
|
+
: /^(Token |设备|License |ASR )/.test(error.message) ? error.message : 'ASR 服务暂不可用,请稍后重试' };
|
|
81
|
+
} finally { clearTimeout(timer); }
|
|
82
|
+
}
|
|
83
|
+
async translate({ sn, service: capturedService, ...request }) {
|
|
84
|
+
const service = capturedService ?? await this.service();
|
|
85
|
+
const signal = AbortSignal.any([request.signal, this.lifetime.signal]);
|
|
86
|
+
signal.throwIfAborted();
|
|
87
|
+
return translateText({ ...request, signal, getToken: this.provider(sn, service), userId: service.userId,
|
|
88
|
+
url: service.translateUrl, fetchImpl: this.dependencies.fetchImpl ?? globalThis.fetch });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export async function apply(ctx, config = {}) {
|
|
92
|
+
ctx.effect(() => ctx.typert.register(TYPERT));
|
|
93
|
+
const controller = new MouseController(ctx, config, { desktop: new DesktopPresentation() });
|
|
94
|
+
await controller.initialized;
|
|
95
|
+
void controller.manager.start();
|
|
96
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { BUILTIN_ASR } from '../asr/config.mjs';
|
|
3
|
+
|
|
4
|
+
export const STORE_KEY = 'dsh-asr/config';
|
|
5
|
+
|
|
6
|
+
export class ServiceStore {
|
|
7
|
+
constructor(credentials) { this.credentials = credentials; }
|
|
8
|
+
async state() {
|
|
9
|
+
// 白名单重建旧记录,只保留调用身份;不读取旧服务或复制其中的凭据。
|
|
10
|
+
const record = await this.credentials.modifyRecord(STORE_KEY, current => ({
|
|
11
|
+
kind: 'grant', payload: {
|
|
12
|
+
version: 2,
|
|
13
|
+
userId: typeof current?.payload?.userId === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(current.payload.userId)
|
|
14
|
+
? current.payload.userId : randomUUID(),
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
return record.payload;
|
|
18
|
+
}
|
|
19
|
+
async catalog() {
|
|
20
|
+
await this.state();
|
|
21
|
+
return { revision: 0, activeId: 'builtin', services: [{ ...BUILTIN_ASR, id: 'builtin', builtin: true, configured: true }] };
|
|
22
|
+
}
|
|
23
|
+
async resolve() { return { ...BUILTIN_ASR, id: 'builtin', userId: (await this.state()).userId }; }
|
|
24
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { REC_LANG_LIST, TRANS_FROM_LANG_LIST, TRANS_TO_LANG_LIST } from './languages.mjs';
|
|
3
|
+
import { DPI_LIST, M_KEY_FUNC_LIST, M_KEY_SEARCH_URL_LIST } from './mouse-settings.mjs';
|
|
4
|
+
export { REC_LANG_LIST, TRANS_FROM_LANG_LIST, TRANS_TO_LANG_LIST, DPI_LIST, M_KEY_FUNC_LIST, M_KEY_SEARCH_URL_LIST };
|
|
5
|
+
export const languageKey = ({ language, accent, rlang }) => JSON.stringify([language, accent, rlang]);
|
|
6
|
+
const choice = list => z.string().refine(value => list.some(item => item.value === value), '选项不存在');
|
|
7
|
+
const recognitionValueSchema = z.object({ language: z.string(), accent: z.string(), rlang: z.string() }).strict();
|
|
8
|
+
export const recognitionSchema = recognitionValueSchema
|
|
9
|
+
.refine(value => REC_LANG_LIST.some(item => languageKey(item) === languageKey(value)), '识别语言不存在');
|
|
10
|
+
export function webUrl(value) {
|
|
11
|
+
let text = value.trim();
|
|
12
|
+
const hasProtocol = /^https?:\/\//i.test(text);
|
|
13
|
+
if (!hasProtocol) {
|
|
14
|
+
// A host followed by a numeric port is not a URI scheme. The prefix is for parsing only.
|
|
15
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(text) && !/^[^:/?#]+:\d+(?:[/?#]|$)/u.test(text)) {
|
|
16
|
+
throw new Error('请填写有效的 HTTP/HTTPS 网址');
|
|
17
|
+
}
|
|
18
|
+
if (/^https?:/i.test(text)) throw new Error('请填写有效的网址');
|
|
19
|
+
text = `https://${text}`;
|
|
20
|
+
}
|
|
21
|
+
if (!/^https?:\/\/[^/\\\s]/i.test(text) || value.trim().length > 4096) throw new Error('请填写有效的网址(最多 4096 字符)');
|
|
22
|
+
let url;
|
|
23
|
+
try { url = new URL(text); } catch { throw new Error('请填写完整 HTTP/HTTPS 地址'); }
|
|
24
|
+
if (!['http:', 'https:'].includes(url.protocol) || !url.hostname || url.username || url.password || /[\\\u0000-\u0020\u007f]/u.test(text)) {
|
|
25
|
+
throw new Error('请填写不含凭据和空白字符的 HTTP/HTTPS 地址');
|
|
26
|
+
}
|
|
27
|
+
if (!hasProtocol && !url.hostname.includes('.') && !url.hostname.startsWith('[') && url.hostname !== 'localhost') {
|
|
28
|
+
throw new Error('请填写有效的域名或 IP 地址');
|
|
29
|
+
}
|
|
30
|
+
if (!url.hostname.startsWith('[') && url.hostname.replace(/\.$/, '').split('.').some(label => !/^[a-z\d](?:[a-z\d-]*[a-z\d])?$/i.test(label))) {
|
|
31
|
+
throw new Error('请填写有效的域名或 IP 地址');
|
|
32
|
+
}
|
|
33
|
+
return value.trim();
|
|
34
|
+
}
|
|
35
|
+
export const preferencesSchema = z.object({
|
|
36
|
+
recognition: recognitionSchema, punctuation: z.boolean(),
|
|
37
|
+
from: choice(TRANS_FROM_LANG_LIST), to: choice(TRANS_TO_LANG_LIST),
|
|
38
|
+
dpi: choice(DPI_LIST), mAction: choice(M_KEY_FUNC_LIST),
|
|
39
|
+
searchUrl: choice(M_KEY_SEARCH_URL_LIST), linkUrl: z.string().max(4096),
|
|
40
|
+
speechAction: z.enum(['voice_input', 'translate']), aiAction: z.literal('openAi'), aiAutoSend: z.boolean(),
|
|
41
|
+
}).strict().superRefine((value, ctx) => {
|
|
42
|
+
if (value.linkUrl || value.mAction === 'openWebUrl') {
|
|
43
|
+
try { webUrl(value.linkUrl); } catch (error) { ctx.addIssue({ code: 'custom', path: ['linkUrl'], message: error.message }); }
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// 读取旧语言值供用户重新选择;已移除的 M 键动作回退默认值,写入仍严格校验。
|
|
47
|
+
export const storedPreferencesSchema = preferencesSchema.safeExtend({
|
|
48
|
+
recognition: recognitionValueSchema, from: z.string(), to: z.string(),
|
|
49
|
+
mAction: choice(M_KEY_FUNC_LIST).catch(() => defaultPreferences().mAction),
|
|
50
|
+
aiAutoSend: z.boolean().default(true),
|
|
51
|
+
});
|
|
52
|
+
export const defaultPreferences = () => ({
|
|
53
|
+
recognition: { language: 'zh_cn', accent: 'mandarin', rlang: '' }, punctuation: true,
|
|
54
|
+
from: 'cn', to: 'en', dpi: '1600', mAction: 'enter',
|
|
55
|
+
searchUrl: M_KEY_SEARCH_URL_LIST[0].value, linkUrl: '', speechAction: 'voice_input', aiAction: 'openAi', aiAutoSend: true,
|
|
56
|
+
});
|
|
57
|
+
export const snSchema = z.string().min(1).max(128).refine(value =>
|
|
58
|
+
!/^(usb-|ble-)/i.test(value) && !/[\u0000-\u0020]/u.test(value) && !['__proto__', 'prototype', 'constructor'].includes(value), '设备 SN 未确认');
|
|
59
|
+
export const isStableSn = value => snSchema.safeParse(value).success;
|
|
60
|
+
export function searchAddress(prefix, text) {
|
|
61
|
+
if (!M_KEY_SEARCH_URL_LIST.some(item => item.value === prefix)) throw new Error('搜索引擎不存在');
|
|
62
|
+
if (!text.trim()) throw new Error('未识别到语音');
|
|
63
|
+
return prefix + encodeURIComponent(text.trim());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function sourceRecognitionLanguage(from) {
|
|
67
|
+
const locale = TRANS_FROM_LANG_LIST.find(item => item.value === from)?.locale;
|
|
68
|
+
return REC_LANG_LIST.find(item => item.language === locale && item.accent === 'mandarin' && item.rlang === '');
|
|
69
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// 语言选项、排序及字段约定见 specs/mouse-settings.md;修改时同步更新。
|
|
2
|
+
|
|
3
|
+
// 语音识别语言列表:language 语言代码,accent 方言,rlang 字体(简体/繁体)
|
|
4
|
+
export const REC_LANG_LIST = [
|
|
5
|
+
{ language: 'zh_cn', accent: 'mandarin', rlang: '', label: '普通话', zh_name: '普通话' },
|
|
6
|
+
{ language: 'en_us', accent: 'mandarin', rlang: '', label: 'English', zh_name: '英语' },
|
|
7
|
+
{ language: 'zh_cn', accent: 'dongbeiese', rlang: '', label: '东北话', zh_name: '东北话' },
|
|
8
|
+
{ language: 'zh_cn', accent: 'gansunese', rlang: '', label: '甘肃话', zh_name: '甘肃话' },
|
|
9
|
+
{ language: 'zh_cn', accent: 'cantonese', rlang: '', label: '广东话', zh_name: '广东话' },
|
|
10
|
+
{ language: 'zh_cn', accent: 'guizhounese', rlang: '', label: '贵州话', zh_name: '贵州话' },
|
|
11
|
+
{ language: 'zh_cn', accent: 'hebeinese', rlang: '', label: '河北话', zh_name: '河北话' },
|
|
12
|
+
{ language: 'zh_cn', accent: 'henannese', rlang: '', label: '河南话', zh_name: '河南话' },
|
|
13
|
+
{ language: 'zh_cn', accent: 'minnanese', rlang: '', label: '闽南话', zh_name: '闽南话' },
|
|
14
|
+
{ language: 'zh_cn', accent: 'ningxianese', rlang: '', label: '宁夏话', zh_name: '宁夏话' },
|
|
15
|
+
{ language: 'zh_cn', accent: 'shandongnese', rlang: '', label: '山东话', zh_name: '山东话' },
|
|
16
|
+
{ language: 'zh_cn', accent: 'shanxinese', rlang: '', label: '陕西话', zh_name: '陕西话' },
|
|
17
|
+
{ language: 'zh_cn', accent: 'shanghainese', rlang: '', label: '上海话', zh_name: '上海话' },
|
|
18
|
+
{ language: 'zh_cn', accent: 'lmz', rlang: '', label: '四川话', zh_name: '四川话' },
|
|
19
|
+
{ language: 'zh_cn', accent: 'tianjinese', rlang: '', label: '天津话', zh_name: '天津话' },
|
|
20
|
+
{ language: 'zh_cn', accent: 'yunnanese', rlang: '', label: '云南话', zh_name: '云南话' },
|
|
21
|
+
{ language: 'zh_cn', accent: 'mandarin', rlang: 'zh-hk', label: '普通话(繁體)', zh_name: '普通话(繁体)' },
|
|
22
|
+
{ language: 'ar_il', accent: 'mandarin', rlang: '', label: 'عربي', zh_name: '阿拉伯语' },
|
|
23
|
+
{ language: 'pl_pl', accent: 'mandarin', rlang: '', label: 'Polski', zh_name: '波兰语' },
|
|
24
|
+
{ language: 'fa_IR', accent: 'mandarin', rlang: '', label: 'فارسی', zh_name: '波斯语' },
|
|
25
|
+
{ language: 'da_DK', accent: 'mandarin', rlang: '', label: 'Dansk', zh_name: '丹麦语' },
|
|
26
|
+
{ language: 'de_DE', accent: 'mandarin', rlang: '', label: 'Deutsch', zh_name: '德语' },
|
|
27
|
+
{ language: 'ru-ru', accent: 'mandarin', rlang: '', label: 'Русский', zh_name: '俄语' },
|
|
28
|
+
{ language: 'fr_fr', accent: 'mandarin', rlang: '', label: 'Français', zh_name: '法语' },
|
|
29
|
+
{ language: 'fi_fi', accent: 'mandarin', rlang: '', label: 'Suomi', zh_name: '芬兰语' },
|
|
30
|
+
{ language: 'ko_kr', accent: 'mandarin', rlang: '', label: '한국어', zh_name: '韩语' },
|
|
31
|
+
{ language: 'nl_NL', accent: 'mandarin', rlang: '', label: 'Nederlands', zh_name: '荷兰语' },
|
|
32
|
+
{ language: 'cs_CZ', accent: 'mandarin', rlang: '', label: 'Čeština', zh_name: '捷克语' },
|
|
33
|
+
{ language: 'ms_MY', accent: 'mandarin', rlang: '', label: 'Bahasa Melayu', zh_name: '马来西亚语' },
|
|
34
|
+
{ language: 'pt_PT', accent: 'mandarin', rlang: '', label: 'Português', zh_name: '葡萄牙语' },
|
|
35
|
+
{ language: 'ja_jp', accent: 'mandarin', rlang: '', label: '日本語', zh_name: '日语' },
|
|
36
|
+
{ language: 'sv_SE', accent: 'mandarin', rlang: '', label: 'Svenska', zh_name: '瑞典语' },
|
|
37
|
+
{ language: 'th_TH', accent: 'mandarin', rlang: '', label: 'ไทย', zh_name: '泰语' },
|
|
38
|
+
{ language: 'tr_TR', accent: 'mandarin', rlang: '', label: 'Türkçe', zh_name: '土耳其语' },
|
|
39
|
+
{ language: 'es_es', accent: 'mandarin', rlang: '', label: 'Español', zh_name: '西班牙语' },
|
|
40
|
+
{ language: 'he_il', accent: 'mandarin', rlang: '', label: 'עברית', zh_name: '希伯来语' },
|
|
41
|
+
{ language: 'el_GR', accent: 'mandarin', rlang: '', label: 'Ελληνικά', zh_name: '希腊语' },
|
|
42
|
+
{ language: 'it_IT', accent: 'mandarin', rlang: '', label: 'Italiano', zh_name: '意大利语' },
|
|
43
|
+
{ language: 'hi_in', accent: 'mandarin', rlang: '', label: 'हिन्दी', zh_name: '印地语' },
|
|
44
|
+
{ language: 'vi_VN', accent: 'mandarin', rlang: '', label: 'Tiếng Việt', zh_name: '越南语' },
|
|
45
|
+
{ language: 'uz_UZ', accent: 'mandarin', rlang: '', label: 'Uzbek', zh_name: '乌兹别克语' },
|
|
46
|
+
{ language: 'km_KH', accent: 'mandarin', rlang: '', label: 'ភាសាខ្មែរ', zh_name: '高棉语' },
|
|
47
|
+
{ language: 'id_ID', accent: 'mandarin', rlang: '', label: 'Bahasa Indonesia', zh_name: '印尼语' },
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
// 翻译源语言列表
|
|
51
|
+
export const TRANS_FROM_LANG_LIST = [
|
|
52
|
+
{ value: 'cn', locale: 'zh_cn', label: '中文', zh_name: '中文' },
|
|
53
|
+
{ value: 'en', locale: 'en_us', label: 'English', zh_name: '英文' },
|
|
54
|
+
{ value: 'ja', locale: 'ja_jp', label: '日本語', zh_name: '日语' },
|
|
55
|
+
{ value: 'ko', locale: 'ko_kr', label: '한국어', zh_name: '韩语' },
|
|
56
|
+
{ value: 'de', locale: 'de_DE', label: 'Deutsch', zh_name: '德语' },
|
|
57
|
+
{ value: 'fr', locale: 'fr_fr', label: 'Français', zh_name: '法语' },
|
|
58
|
+
{ value: 'ru', locale: 'ru-ru', label: 'Русский', zh_name: '俄语' },
|
|
59
|
+
{ value: 'ar', locale: 'ar_il', label: 'العربية', zh_name: '阿拉伯语' },
|
|
60
|
+
{ value: 'pl', locale: 'pl_pl', label: 'Polski', zh_name: '波兰语' },
|
|
61
|
+
{ value: 'fa', locale: 'fa_IR', label: 'فارسی', zh_name: '波斯语' },
|
|
62
|
+
{ value: 'da', locale: 'da_DK', label: 'Dansk', zh_name: '丹麦语' },
|
|
63
|
+
{ value: 'fi', locale: 'fi_fi', label: 'Suomi', zh_name: '芬兰语' },
|
|
64
|
+
{ value: 'nl', locale: 'nl_NL', label: 'Nederlands', zh_name: '荷兰语' },
|
|
65
|
+
{ value: 'cs', locale: 'cs_CZ', label: 'Čeština', zh_name: '捷克语' },
|
|
66
|
+
{ value: 'ms', locale: 'ms_MY', label: 'Bahasa Melayu', zh_name: '马来西亚语' },
|
|
67
|
+
{ value: 'pt', locale: 'pt_PT', label: 'Português', zh_name: '葡萄牙语' },
|
|
68
|
+
{ value: 'sv', locale: 'sv_SE', label: 'Svenska', zh_name: '瑞典语' },
|
|
69
|
+
{ value: 'th', locale: 'th_TH', label: 'ไทย', zh_name: '泰语' },
|
|
70
|
+
{ value: 'tr', locale: 'tr_TR', label: 'Türkçe', zh_name: '土耳其语' },
|
|
71
|
+
{ value: 'es', locale: 'es_es', label: 'Español', zh_name: '西班牙语' },
|
|
72
|
+
{ value: 'he', locale: 'he_il', label: 'עברית', zh_name: '希伯来语' },
|
|
73
|
+
{ value: 'el', locale: 'el_GR', label: 'Ελληνικά', zh_name: '希腊语' },
|
|
74
|
+
{ value: 'it', locale: 'it_IT', label: 'Italiano', zh_name: '意大利语' },
|
|
75
|
+
{ value: 'hi', locale: 'hi_in', label: 'हिन्दी', zh_name: '印地语' },
|
|
76
|
+
{ value: 'vi', locale: 'vi_VN', label: 'Tiếng Việt', zh_name: '越南语' },
|
|
77
|
+
{ value: 'uz', locale: 'uz_UZ', label: 'Uzbek', zh_name: '乌兹别克语' },
|
|
78
|
+
{ value: 'km', locale: 'km_KH', label: 'ភាសាខ្មែរ', zh_name: '高棉语' },
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
// 翻译目标语言列表
|
|
82
|
+
export const TRANS_TO_LANG_LIST = [
|
|
83
|
+
{ value: 'cn', label: '中文', zh_name: '中文' },
|
|
84
|
+
{ value: 'en', label: 'English', zh_name: '英文' },
|
|
85
|
+
{ value: 'ja', label: '日本語', zh_name: '日语' },
|
|
86
|
+
{ value: 'ko', label: '한국어', zh_name: '韩语' },
|
|
87
|
+
{ value: 'de', label: 'Deutsch', zh_name: '德语' },
|
|
88
|
+
{ value: 'fr', label: 'Français', zh_name: '法语' },
|
|
89
|
+
{ value: 'ru', label: 'Русский', zh_name: '俄语' },
|
|
90
|
+
{ value: 'ar', label: 'العربية', zh_name: '阿拉伯语' },
|
|
91
|
+
{ value: 'pl', label: 'Polski', zh_name: '波兰语' },
|
|
92
|
+
{ value: 'fa', label: 'فارسی', zh_name: '波斯语' },
|
|
93
|
+
{ value: 'da', label: 'Dansk', zh_name: '丹麦语' },
|
|
94
|
+
{ value: 'fi', label: 'Suomi', zh_name: '芬兰语' },
|
|
95
|
+
{ value: 'nl', label: 'Nederlands', zh_name: '荷兰语' },
|
|
96
|
+
{ value: 'cs', label: 'Čeština', zh_name: '捷克语' },
|
|
97
|
+
{ value: 'ms', label: 'Bahasa Melayu', zh_name: '马来西亚语' },
|
|
98
|
+
{ value: 'mn', label: 'Монгол', zh_name: '蒙古语' },
|
|
99
|
+
{ value: 'pt', label: 'Português', zh_name: '葡萄牙语' },
|
|
100
|
+
{ value: 'sv', label: 'Svenska', zh_name: '瑞典语' },
|
|
101
|
+
{ value: 'th', label: 'ไทย', zh_name: '泰语' },
|
|
102
|
+
{ value: 'tr', label: 'Türkçe', zh_name: '土耳其语' },
|
|
103
|
+
{ value: 'es', label: 'Español', zh_name: '西班牙语' },
|
|
104
|
+
{ value: 'he', label: 'עברית', zh_name: '希伯来语' },
|
|
105
|
+
{ value: 'el', label: 'Ελληνικά', zh_name: '希腊语' },
|
|
106
|
+
{ value: 'it', label: 'Italiano', zh_name: '意大利语' },
|
|
107
|
+
{ value: 'hi', label: 'हिन्दी', zh_name: '印地语' },
|
|
108
|
+
{ value: 'vi', label: 'Tiếng Việt', zh_name: '越南语' },
|
|
109
|
+
{ value: 'uz', label: 'Uzbek', zh_name: '乌兹别克语' },
|
|
110
|
+
{ value: 'km', label: 'ភាសាខ្មែរ', zh_name: '高棉语' },
|
|
111
|
+
]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// 鼠标设置选项及顺序见 specs/mouse-settings.md;修改时同步更新。
|
|
2
|
+
export const DPI_LIST = [
|
|
3
|
+
{ label: '800', value: '800' },
|
|
4
|
+
{ label: '1200', value: '1200' },
|
|
5
|
+
{ label: '1600', value: '1600' },
|
|
6
|
+
{ label: '2400', value: '2400' },
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
export const M_KEY_FUNC_LIST = [
|
|
10
|
+
{ label: '回车', value: 'enter' },
|
|
11
|
+
{ label: '后退', value: 'backspace' },
|
|
12
|
+
{ label: '语音翻译', value: 'translate' },
|
|
13
|
+
{ label: '语音打字', value: 'voice_input' },
|
|
14
|
+
{ label: '语音搜索', value: 'speechSearch' },
|
|
15
|
+
{ label: '一键链接', value: 'openWebUrl' },
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
export const M_KEY_SEARCH_URL_LIST = [
|
|
19
|
+
{ label: '百度', value: 'https://www.baidu.com/baidu?wd=' },
|
|
20
|
+
{ label: 'bing', value: 'https://www.bing.com/search?q=' },
|
|
21
|
+
{ label: 'google', value: 'https://www.google.com/search?q=' },
|
|
22
|
+
]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { preferencesSchema, storedPreferencesSchema, snSchema } from './devices.mjs';
|
|
3
|
+
|
|
4
|
+
export const PACKAGE = '@sonicloud/dsh-sonicloud-device';
|
|
5
|
+
const text = z.string().max(4096);
|
|
6
|
+
const id = z.string().max(80);
|
|
7
|
+
const catalog = z.object({ revision: z.number().int(), activeId: id, services: z.array(z.object({
|
|
8
|
+
id, name: text, streamUrl: text, tokenUrl: text, translateUrl: text, builtin: z.boolean(), configured: z.boolean(),
|
|
9
|
+
}).strict()) });
|
|
10
|
+
const device = z.object({
|
|
11
|
+
id: text, sn: z.string(), type: z.string(), name: z.string(), connection: z.enum(['usb', 'ble']),
|
|
12
|
+
battery: z.number().nullable(), identityConfirmed: z.boolean(), dpiState: z.string(),
|
|
13
|
+
dpiRaw: z.number().optional(), revision: z.number().optional(), preferences: storedPreferencesSchema.optional(),
|
|
14
|
+
});
|
|
15
|
+
const devices = z.object({ status: text, devices: z.array(device), recognitionLanguages: z.array(z.string()), translationReady: z.boolean() });
|
|
16
|
+
const session = { sessionId: z.string() };
|
|
17
|
+
const event = z.discriminatedUnion('type', [
|
|
18
|
+
devices.extend({ type: z.literal('devices') }),
|
|
19
|
+
z.object({ type: z.literal('notice'), message: text }),
|
|
20
|
+
z.object({ type: z.literal('request'), ...session, sn: z.string(), action: z.enum(['voice_input', 'translate', 'speechSearch']) }),
|
|
21
|
+
z.object({ type: z.literal('phase'), ...session, phase: z.enum(['recording', 'finishing', 'translating']) }),
|
|
22
|
+
z.object({ type: z.literal('preview'), ...session, text: z.string().max(65536) }),
|
|
23
|
+
z.object({ type: z.literal('result'), ...session, text: z.string().max(65536) }),
|
|
24
|
+
z.object({ type: z.literal('finished'), ...session }),
|
|
25
|
+
z.object({ type: z.literal('cancelled'), ...session }),
|
|
26
|
+
z.object({ type: z.literal('failed'), ...session, message: text }),
|
|
27
|
+
]);
|
|
28
|
+
const codec = (name, schema) => ({ mode: 'strict', typeSymbol: `${PACKAGE}#${name}`, create: () => schema });
|
|
29
|
+
const define = (method, params, result, extra = {}) => ({
|
|
30
|
+
id: `${PACKAGE}#asr/${method}`, namespace: 'asr', service: 'sinicloudAsr', method,
|
|
31
|
+
invocation: { kind: 'direct' },
|
|
32
|
+
parameters: params.map(([name, schema]) => ({ name, wire: name, source: 'json', codec: codec(`${method}/${name}`, schema) })),
|
|
33
|
+
result: codec(`${method}/result`, result), ...extra,
|
|
34
|
+
});
|
|
35
|
+
export const REMOTE = {
|
|
36
|
+
package: PACKAGE,
|
|
37
|
+
descriptors: [
|
|
38
|
+
define('catalog', [], catalog),
|
|
39
|
+
define('devices', [], devices),
|
|
40
|
+
define('saveDevice', [['sn', snSchema], ['revision', z.number().int().nonnegative()], ['preferences', preferencesSchema]],
|
|
41
|
+
z.object({ revision: z.number(), preferences: preferencesSchema, message: text })),
|
|
42
|
+
define('watch', [['clientId', id]], event, { mode: 'stream', cancellation: { parameter: 'signal' } }),
|
|
43
|
+
define('accept', [['clientId', id], ['sessionId', id]], z.boolean()),
|
|
44
|
+
define('cancel', [['clientId', id], ['sessionId', id]], z.boolean()),
|
|
45
|
+
define('watchAi', [['clientId', id]], z.object({
|
|
46
|
+
requestId: id, sessionId: id, operation: z.enum(['prepare', 'insert', 'release']),
|
|
47
|
+
expiresAt: z.number().optional(), text: z.string().max(65536).optional(), autoSend: z.boolean().optional(),
|
|
48
|
+
}), { mode: 'stream', cancellation: { parameter: 'signal' } }),
|
|
49
|
+
define('answerAi', [['clientId', id], ['requestId', id], ['ok', z.boolean()]], z.boolean()),
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
export const TYPERT = {
|
|
53
|
+
package: PACKAGE, face: 'host', schemas: [],
|
|
54
|
+
model: { services: [], events: [], objects: [] }, invocations: REMOTE.descriptors,
|
|
55
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Mutable interim text, immutable ordered sentence boundaries. No draft writes. */
|
|
2
|
+
export class Transcript {
|
|
3
|
+
sentences = new Map();
|
|
4
|
+
interim = '';
|
|
5
|
+
update(event) {
|
|
6
|
+
if (event.final) {
|
|
7
|
+
this.sentences.set(`${event.begin}:${event.end}`, { begin: event.begin, end: event.end, text: event.text });
|
|
8
|
+
this.interim = '';
|
|
9
|
+
} else {
|
|
10
|
+
if ([...this.sentences.values()].some(sentence => sentence.begin === event.begin)) return;
|
|
11
|
+
this.interim = event.text;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
finalText() { return [...this.sentences.values()].sort((a, b) => a.begin - b.begin || a.end - b.end).map(item => item.text).join(''); }
|
|
15
|
+
preview() { return this.finalText() + this.interim; }
|
|
16
|
+
}
|