40760aa884
- server:Go 网关(WS 流式识别中继/计费配额/微信登录支付 mock/反馈/埋点),gummy provider 已真实联调 - desktop:Tauri 2(全局快捷键 push-to-talk/浮层/托盘/设置/登录购买/反馈/首启引导) - android:Compose 主 App + IME(键盘内录音直传) - ios:App + 键盘扩展(1A spike 实证键盘内不可录音,走 deep link 听写) - design/design-pipeline:设计系统 + token 导出 iOS/Android 主题 - doc:前后端设计文档(HTML);web:官网宣传页;todo:任务看板 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
54 lines
2.1 KiB
React
54 lines
2.1 KiB
React
// 识别浮层窗口:深色玻璃、不抢焦点;状态完全由 Rust 事件驱动。
|
|
// listening / text 两态 + 错误态文案,规格见 doc/frontend-design.html 5.1/5.2
|
|
import { useEffect, useState } from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
import '@dudu/design/styles.css';
|
|
import { RecognitionOverlay } from '@dudu/design/components/voice/RecognitionOverlay';
|
|
import { listen } from '../shared/tauri';
|
|
|
|
const ERR_TEXT = {
|
|
QUOTA_EXCEEDED: '今日试用已用完,去购买时长',
|
|
RATE_LIMITED: '操作过于频繁,稍后再试',
|
|
SESSION_LIMIT: '单次最长 3 分钟,松开后可继续',
|
|
ASR_UNAVAILABLE: '识别服务暂不可用,稍后再试',
|
|
NETWORK: '连接中断,松开重试',
|
|
NO_ACCESSIBILITY: '需要辅助功能权限才能上屏,去系统设置开启 dudu',
|
|
};
|
|
|
|
function OverlayApp() {
|
|
const [finalText, setFinalText] = useState('');
|
|
const [partialText, setPartialText] = useState('');
|
|
const [error, setError] = useState('');
|
|
|
|
useEffect(() => {
|
|
const offs = [];
|
|
listen('hotkey', ({ payload }) => {
|
|
if (payload.state === 'down') { setFinalText(''); setPartialText(''); setError(''); }
|
|
}).then((off) => offs.push(off));
|
|
listen('asr', ({ payload }) => {
|
|
if (payload.type === 'partial') setPartialText(payload.text);
|
|
else if (payload.type === 'final') { setFinalText((f) => f + payload.text); setPartialText(''); }
|
|
else if (payload.type === 'error') setError(ERR_TEXT[payload.code] || payload.message || '');
|
|
}).then((off) => offs.push(off));
|
|
return () => offs.forEach((off) => off());
|
|
}, []);
|
|
|
|
const hasText = finalText || partialText;
|
|
return (
|
|
<div style={{ padding: 8 }}>
|
|
{error ? (
|
|
<RecognitionOverlay state="text" finalText="" partialText={error} hint="dudu" />
|
|
) : (
|
|
<RecognitionOverlay
|
|
state={hasText ? 'text' : 'listening'}
|
|
finalText={finalText}
|
|
partialText={partialText}
|
|
hint="松开 ⌘⇧Space 完成输入"
|
|
/>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
createRoot(document.getElementById('root')).render(<OverlayApp />);
|