feat(ai): refine voice input layout and cancellation
This commit is contained in:
@@ -209,6 +209,13 @@ onUnmounted(() => {
|
|||||||
// 文档预览里的过渡组件就是用来验证转场的,因此在预览范围内恢复原定时长。
|
// 文档预览里的过渡组件就是用来验证转场的,因此在预览范围内恢复原定时长。
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
.tui-demo {
|
.tui-demo {
|
||||||
|
// 语音输入的呼吸边框是交互反馈的一部分,预览中恢复动画
|
||||||
|
:deep(.composer.voice-active .form::after) {
|
||||||
|
animation-delay: 0s !important;
|
||||||
|
animation-duration: 1.6s !important;
|
||||||
|
animation-iteration-count: infinite !important;
|
||||||
|
}
|
||||||
|
|
||||||
:deep(.page-transition .push-left-enter-active) {
|
:deep(.page-transition .push-left-enter-active) {
|
||||||
transition-duration: 520ms, 200ms !important;
|
transition-duration: 520ms, 200ms !important;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ demo-preview=../demos/ai-chat-composer/basic.vue
|
|||||||
|
|
||||||
## 语音输入
|
## 语音输入
|
||||||
|
|
||||||
输入框为空且未聚焦时,长按 300ms 进入语音输入:识别文本直接写进输入框,卡片显示主题色呼吸边框,发送按钮变为「松开发送」。松手发送;按住上滑到「取消发送」或「保留识别」按钮后释放,执行对应操作。组件只负责手势与状态展示,识别能力由业务侧接入。
|
开启 `voice-enabled` 后,输入框为空时右侧发送按钮会变成语音按钮(图标 `voice-wave`,文案「语音」)。点击后输入区切换为「按住说话」,右侧按钮变为键盘按钮(图标 `keyboard-1`,文案「输入」);点击键盘按钮回到文本输入。组件只负责手势与状态展示,识别能力由业务侧接入。
|
||||||
|
|
||||||
:::preview 长按语音输入 || 长按输入框说话,识别文本实时进入输入框;松手发送,上滑到按钮可取消或只保留文本;示例接入浏览器 Web Speech API,不支持时可勾选「模拟识别」
|
:::preview 语音输入 || 点击语音按钮进入按住说话,识别文本实时显示在整个控件上方;松手发送,移出按住按钮后松开取消;示例接入浏览器 Web Speech API,不支持时可勾选「模拟识别」
|
||||||
|
|
||||||
demo-preview=../demos/ai-chat-composer/voice.vue
|
demo-preview=../demos/ai-chat-composer/voice.vue
|
||||||
|
|
||||||
@@ -22,29 +22,30 @@ demo-preview=../demos/ai-chat-composer/voice.vue
|
|||||||
|
|
||||||
### 交互约定
|
### 交互约定
|
||||||
|
|
||||||
- 短按(小于 300ms)仍然聚焦文本域;输入框有内容或已聚焦时不接管手势,避免影响编辑与选择
|
- 输入框有内容时右侧仍是发送按钮;只有内容为空且 `voiceState` 为 `idle` 时才显示语音入口
|
||||||
- 触发后整个输入卡片显示主题色呼吸边框,上方浮出「取消发送」和「保留识别」两个投放区
|
- 点击语音按钮进入语音模式,输入区替换为「按住说话」按钮;按住立即触发 `voice-start`,没有长按等待
|
||||||
- `voiceText` 的实时结果直接同步到输入框,不再单独占用语音面板
|
- 按住期间整个输入卡片显示主题色呼吸边框,识别文本实时浮在整个输入卡片上方,最多两行
|
||||||
- 按住时发送按钮文案切换为 `voiceSendHint`,默认「松开发送」
|
- 按住时按钮文案使用 `voiceSendHint`,默认「松开发送」;指针移出按住按钮后改用 `voiceCancelHint`,默认「松开取消」
|
||||||
- 松手时指针在「取消发送」上:触发 `voice-cancel`,组件清空本次识别文本
|
- 松手时指针仍在按住按钮内:触发 `voice-stop`,由业务侧停止识别、取最终结果并发送
|
||||||
- 松手时指针在「保留识别」上:触发 `voice-keep`,停止识别并把文本留在输入框,不发送
|
- 松手时指针已移出按住按钮:触发 `voice-cancel`,业务侧应中断识别并丢弃本次结果
|
||||||
- 松手时指针不在按钮上:触发 `voice-stop`,由业务侧停止识别、取最终结果并决定发送
|
|
||||||
- 指针被系统取消时同样触发 `voice-cancel`
|
- 指针被系统取消时同样触发 `voice-cancel`
|
||||||
|
- 语音模式右侧固定为键盘按钮(图标 `keyboard-1`,文案「输入」),识别中和按住时禁用;点击回到文本输入
|
||||||
|
- 文本输入与按住说话共用同一输入区高度,切换模式时组件不跳动;文本域按内容换行,最少 3 行、最多 6 行,超出后在文本域内滚动
|
||||||
- `voiceEnabled` 默认关闭,需要显式开启
|
- `voiceEnabled` 默认关闭,需要显式开启
|
||||||
|
|
||||||
`voiceState` 由业务侧驱动:
|
`voiceState` 由业务侧驱动:
|
||||||
|
|
||||||
| 状态 | 含义 |
|
| 状态 | 含义 |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `idle` | 未在识别,语音操作区关闭 |
|
| `idle` | 未在识别,可以切换模式或按住说话 |
|
||||||
| `listening` | 正在聆听,实时回写 `voiceText`,组件同步到输入框 |
|
| `listening` | 正在聆听,实时回写 `voiceText`,组件显示在整个控件上方 |
|
||||||
| `processing` | 已松手或选择保留,等待最终识别结果 |
|
| `processing` | 已松手,等待最终识别结果 |
|
||||||
|
|
||||||
识别完成或失败后回到 `idle`,语音操作区随之关闭。组件不会自动发送;正常松手由业务侧在 `voice-stop` 后自行处理。想换文案时用 `voiceSendHint`、`voiceCancelHint`、`voiceKeepHint`、`voiceCancelText`、`voiceKeepText`、`voiceListeningText`、`voiceProcessingText`。
|
识别完成或失败后回到 `idle`。组件不会自动发送;正常松手由业务侧在 `voice-stop` 后自行处理。想换文案时用 `voiceHoldText`、`voiceSendHint`、`voiceCancelHint`、`voiceListeningText`、`voiceProcessingText`。
|
||||||
|
|
||||||
### 组件边界与兼容性
|
### 组件边界与兼容性
|
||||||
|
|
||||||
`AiChatComposer` 不包含 ASR,也不依赖 Web Speech API。`voice-start`、`voice-stop`、`voice-keep`、`voice-cancel` 只表达手势,录音、识别和失败降级全部由调用方决定。上面的 demo 使用 Web Speech API 只是演示适配器,可以整体换成服务端流式识别或原生桥接。
|
`AiChatComposer` 不包含 ASR,也不依赖 Web Speech API。`voice-start`、`voice-stop`、`voice-cancel` 只表达手势,录音、识别和失败降级全部由调用方决定。上面的 demo 使用 Web Speech API 只是演示适配器,可以整体换成服务端流式识别或原生桥接。
|
||||||
|
|
||||||
Web Speech API 的实际兼容性(2026-11):
|
Web Speech API 的实际兼容性(2026-11):
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ Web Speech API 的实际兼容性(2026-11):
|
|||||||
| Firefox 桌面 160+ | 有实现,但生态较新,建议实测;Firefox Android 不支持 |
|
| Firefox 桌面 160+ | 有实现,但生态较新,建议实测;Firefox Android 不支持 |
|
||||||
| SafariViewController / iOS App 内嵌页 | Web Speech API 不可用或不可靠,改用原生桥接 |
|
| SafariViewController / iOS App 内嵌页 | Web Speech API 不可用或不可靠,改用原生桥接 |
|
||||||
|
|
||||||
Web Speech API 还需要 HTTPS(localhost 除外)和麦克风授权;音频会交给浏览器厂商的服务,隐私敏感或企业内网场景不建议使用。iOS 对用户手势要求更严格,如果 `SpeechRecognition.start()` 在 300ms 长按回调里被拒绝,需要在 `pointerdown` 阶段提前启动,或改成点击说话。
|
Web Speech API 还需要 HTTPS(localhost 除外)和麦克风授权;音频会交给浏览器厂商的服务,隐私敏感或企业内网场景不建议使用。组件在 `pointerdown` 时立即触发 `voice-start`,iOS 上应在这个事件里同步调用 `SpeechRecognition.start()`;等异步连接建立后再启动容易被用户手势策略拒绝。
|
||||||
|
|
||||||
生产环境建议把识别放到服务端流式 ASR(WebSocket)或原生语音插件。业务侧只需要按组件契约驱动状态:
|
生产环境建议把识别放到服务端流式 ASR(WebSocket)或原生语音插件。业务侧只需要按组件契约驱动状态:
|
||||||
|
|
||||||
@@ -76,11 +77,6 @@ function onVoiceStop() {
|
|||||||
// 停止录音,等待最终结果;拿到结果后发送
|
// 停止录音,等待最终结果;拿到结果后发送
|
||||||
}
|
}
|
||||||
|
|
||||||
function onVoiceKeep() {
|
|
||||||
voiceState.value = "processing";
|
|
||||||
// 停止录音但不发送,最终结果留在输入框
|
|
||||||
}
|
|
||||||
|
|
||||||
function onVoiceCancel() {
|
function onVoiceCancel() {
|
||||||
voiceState.value = "idle";
|
voiceState.value = "idle";
|
||||||
voiceText.value = "";
|
voiceText.value = "";
|
||||||
@@ -88,7 +84,7 @@ function onVoiceCancel() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`voiceText` 会实时同步到输入框;识别不可用时退回文字输入,不要阻塞发送。
|
`voiceText` 只在按住说话区上方展示,不回写 `v-model`;语音结果由业务侧在 `voice-stop` 后取出并发送。识别不可用时退回文字输入,不要阻塞发送。
|
||||||
|
|
||||||
## 何时使用
|
## 何时使用
|
||||||
|
|
||||||
@@ -96,12 +92,15 @@ function onVoiceCancel() {
|
|||||||
|
|
||||||
## 输入区与操作按钮
|
## 输入区与操作按钮
|
||||||
|
|
||||||
文本域占满整行并随内容自动增高。下一行左侧是新开会话(`chat-add`)和添加附件(`file-add`),右侧根据状态显示纯文本发送或停止按钮。按住语音时发送按钮文案切换为 `voiceSendHint`。
|
文本域占满整行并随内容自动增高。下一行左侧是新开会话(`chat-add`)和添加附件(`file-add`),右侧根据状态显示语音、键盘、发送或停止按钮。
|
||||||
|
|
||||||
| 状态 | 按钮 |
|
| 状态 | 按钮 |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| 空闲且未禁用 | 新开会话、添加附件、发送(`sendText`) |
|
| 空闲、输入框为空且启用 `voiceEnabled` | 语音(`voice-wave`),点击进入语音模式 |
|
||||||
| `isGenerating` 为真 | 停止(`stopText`,危险色) |
|
| 语音模式且未在识别 | 键盘(`keyboard-1`),点击回到文本输入 |
|
||||||
|
| 语音模式正在识别或处理 | 键盘按钮禁用 |
|
||||||
|
| 文本模式且有内容 | 发送(`sendText`) |
|
||||||
|
| `isGenerating` 为真 | 停止(`stopText`,危险色),优先于语音模式 |
|
||||||
| 有 `lastError` 且 `canRetry` | 错误条 + 重试(`retryText`) |
|
| 有 `lastError` 且 `canRetry` | 错误条 + 重试(`retryText`) |
|
||||||
|
|
||||||
生成中或 `disabled` 为真时输入框不可编辑,新开会话、添加附件和 `send` 事件不会触发。
|
生成中或 `disabled` 为真时输入框不可编辑,新开会话、添加附件和 `send` 事件不会触发。
|
||||||
@@ -113,16 +112,15 @@ function onVoiceCancel() {
|
|||||||
- `retry`:点错误条上的重试
|
- `retry`:点错误条上的重试
|
||||||
- `new-conversation`:清空输入框并请求业务侧开始一个新会话
|
- `new-conversation`:清空输入框并请求业务侧开始一个新会话
|
||||||
- `add-attachment`:请求业务侧添加附件
|
- `add-attachment`:请求业务侧添加附件
|
||||||
- `voice-start`:长按达到阈值,可以开始录音或启动识别
|
- `voice-start`:按住「按住说话」按钮时立即触发,可以开始录音或启动识别
|
||||||
- `voice-stop`:松手且不在操作按钮上,可以停止识别并取最终结果
|
- `voice-stop`:松手且不在取消区,可以停止识别并取最终结果
|
||||||
- `voice-keep`:松手在「保留识别」上,停止识别,文本留在输入框但不发送
|
- `voice-cancel`:松手时指针已移出按住按钮,或指针被系统取消;业务侧应中断识别并丢弃本次结果
|
||||||
- `voice-cancel`:松手在「取消发送」上,或指针被系统取消;组件会清空输入框,业务侧应丢弃本次语音
|
|
||||||
|
|
||||||
输入框内容用 `v-model` 绑定,`maxLength` 默认 2000。
|
输入框内容用 `v-model` 绑定,`maxLength` 默认 2000。语音识别结果只通过 `voiceText` 展示,不写入 `v-model`。
|
||||||
|
|
||||||
## 自定义插槽
|
## 自定义插槽
|
||||||
|
|
||||||
`send`、`stop`、`error` 三个插槽可以替换对应区域的渲染,都带作用域参数(`disabled`、`onSend`、`onStop`、`error`、`canRetry`)。
|
`send`、`stop`、`error` 三个插槽可以替换对应区域的渲染,都带作用域参数(`disabled`、`onSend`、`onStop`、`error`、`canRetry`)。`send` 插槽只用于文本发送;语音入口和键盘切换按钮由组件内置。
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<p
|
<p
|
||||||
class="voice-placeholder"
|
class="voice-placeholder"
|
||||||
:class="{ hidden: voiceState !== 'idle' }"
|
:class="{ hidden: voiceState !== 'idle' }"
|
||||||
v-text="'长按下方输入框开始语音输入'"
|
v-text="'点击语音按钮,按住下方按钮说话;移出按钮后松开取消'"
|
||||||
/>
|
/>
|
||||||
<ai-chat-composer
|
<ai-chat-composer
|
||||||
v-model="draft"
|
v-model="draft"
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
@send="sendMessage"
|
@send="sendMessage"
|
||||||
@voice-start="onVoiceStart"
|
@voice-start="onVoiceStart"
|
||||||
@voice-stop="onVoiceStop"
|
@voice-stop="onVoiceStop"
|
||||||
@voice-keep="onVoiceKeep"
|
|
||||||
@voice-cancel="onVoiceCancel"
|
@voice-cancel="onVoiceCancel"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -87,16 +86,15 @@ let recognition: SpeechRecognitionLike | undefined;
|
|||||||
let finalText = "";
|
let finalText = "";
|
||||||
let mockStepTimer: number | undefined;
|
let mockStepTimer: number | undefined;
|
||||||
let mockFinishTimer: number | undefined;
|
let mockFinishTimer: number | undefined;
|
||||||
let sendOnFinish = true;
|
|
||||||
|
|
||||||
const hint = computed(() => {
|
const hint = computed(() => {
|
||||||
if (mockEnabled.value) {
|
if (mockEnabled.value) {
|
||||||
return "模拟模式:按住输入框说话,松手发送;上滑到按钮可选择取消或保留。";
|
return "模拟模式:按住按钮说话,松手发送;移出按钮后松开取消。";
|
||||||
}
|
}
|
||||||
if (!supported.value) {
|
if (!supported.value) {
|
||||||
return "当前浏览器不支持语音识别,已切换为模拟。";
|
return "当前浏览器不支持语音识别,已切换为模拟。";
|
||||||
}
|
}
|
||||||
return "长按输入框说话,松手发送;上滑到「取消发送」或「保留识别」按钮释放。";
|
return "按住按钮说话,识别文本显示在整个控件上方;松手发送,移出按钮后松开取消。";
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 获取浏览器实现;Chrome 与 Edge 需要 webkit 前缀。 */
|
/** 获取浏览器实现;Chrome 与 Edge 需要 webkit 前缀。 */
|
||||||
@@ -134,7 +132,6 @@ function sendMessage(message: string): void {
|
|||||||
function onVoiceStart(): void {
|
function onVoiceStart(): void {
|
||||||
voiceText.value = "";
|
voiceText.value = "";
|
||||||
finalText = "";
|
finalText = "";
|
||||||
sendOnFinish = true;
|
|
||||||
if (mockEnabled.value || !supported.value) {
|
if (mockEnabled.value || !supported.value) {
|
||||||
startMock();
|
startMock();
|
||||||
return;
|
return;
|
||||||
@@ -162,12 +159,6 @@ function onVoiceStart(): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onVoiceStop(): void {
|
function onVoiceStop(): void {
|
||||||
sendOnFinish = true;
|
|
||||||
stopVoice();
|
|
||||||
}
|
|
||||||
|
|
||||||
function onVoiceKeep(): void {
|
|
||||||
sendOnFinish = false;
|
|
||||||
stopVoice();
|
stopVoice();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +188,7 @@ function onVoiceCancel(): void {
|
|||||||
resetVoice();
|
resetVoice();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 实时拼接最终结果与临时结果,组件会同步到输入框。 */
|
/** 实时拼接最终结果与临时结果,组件在按住说话区上方展示。 */
|
||||||
function handleResult(event: SpeechResultEvent): void {
|
function handleResult(event: SpeechResultEvent): void {
|
||||||
let interim = "";
|
let interim = "";
|
||||||
for (let index = event.resultIndex; index < event.results.length; index += 1) {
|
for (let index = event.resultIndex; index < event.results.length; index += 1) {
|
||||||
@@ -236,15 +227,7 @@ function handleEnd(): void {
|
|||||||
|
|
||||||
function finishVoice(): void {
|
function finishVoice(): void {
|
||||||
const message = voiceText.value.trim();
|
const message = voiceText.value.trim();
|
||||||
const shouldSend = sendOnFinish;
|
|
||||||
resetVoice();
|
resetVoice();
|
||||||
if (!shouldSend) {
|
|
||||||
if (message) {
|
|
||||||
draft.value = message;
|
|
||||||
}
|
|
||||||
push("已保留识别结果,可继续编辑");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +278,6 @@ function resetVoice(): void {
|
|||||||
voiceState.value = "idle";
|
voiceState.value = "idle";
|
||||||
voiceText.value = "";
|
voiceText.value = "";
|
||||||
finalText = "";
|
finalText = "";
|
||||||
sendOnFinish = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="composer" :class="{ 'voice-active': voiceActive }">
|
<div class="composer" :class="{ 'voice-active': voicePressing }">
|
||||||
<div v-if="props.lastError" class="error-bar">
|
<div v-if="props.lastError" class="error-bar">
|
||||||
<slot name="error" :error="props.lastError" :can-retry="props.canRetry">
|
<slot name="error" :error="props.lastError" :can-retry="props.canRetry">
|
||||||
<span class="error-text" v-text="props.lastError" />
|
<span class="error-text" v-text="props.lastError" />
|
||||||
@@ -13,45 +13,38 @@
|
|||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
<t-form class="form glass-white" @submit="submitMessage">
|
<t-form class="form glass-white" @submit="submitMessage">
|
||||||
<div v-if="voiceActionsVisible" class="voice-actions" role="group" aria-label="语音操作">
|
<div v-if="voiceMode && (voiceTranscript || voiceTranscriptHint)" class="voice-transcript" aria-live="polite">
|
||||||
<div class="voice-status" aria-live="polite">
|
<div class="voice-wave" aria-hidden="true">
|
||||||
<div class="voice-wave" aria-hidden="true">
|
<span v-for="index in 5" :key="index" :style="`--i: ${index}`" />
|
||||||
<span v-for="index in 5" :key="index" :style="`--i: ${index}`" />
|
|
||||||
</div>
|
|
||||||
<span class="voice-status-text" v-text="voiceStatusText" />
|
|
||||||
</div>
|
|
||||||
<div class="voice-buttons">
|
|
||||||
<div ref="cancelActionRef" class="voice-action cancel" :class="{ active: willCancel }">
|
|
||||||
<t-icon name="close" size="small" />
|
|
||||||
<span v-text="props.voiceCancelText" />
|
|
||||||
</div>
|
|
||||||
<div ref="keepActionRef" class="voice-action keep" :class="{ active: willKeep }">
|
|
||||||
<t-icon name="check" size="small" />
|
|
||||||
<span v-text="props.voiceKeepText" />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<p v-if="voiceTranscript" class="voice-text" v-text="voiceTranscript" />
|
||||||
|
<p v-else class="voice-placeholder" v-text="voiceTranscriptHint" />
|
||||||
</div>
|
</div>
|
||||||
<div class="input-wrap">
|
<div class="input-wrap">
|
||||||
<t-textarea
|
<t-textarea
|
||||||
ref="textareaRef"
|
ref="textareaRef"
|
||||||
v-model="draft"
|
v-model="draft"
|
||||||
class="input"
|
class="input"
|
||||||
:autosize="{ minRows: 3, maxRows: 6 }"
|
:class="{ 'voice-input-hidden': voiceMode }"
|
||||||
:disabled="props.isGenerating || props.disabled"
|
:autosize="{ minRows: 2, maxRows: 6 }"
|
||||||
|
:disabled="voiceMode || props.isGenerating || props.disabled"
|
||||||
:maxlength="props.maxLength"
|
:maxlength="props.maxLength"
|
||||||
:placeholder="props.placeholder"
|
:placeholder="props.placeholder"
|
||||||
@focus="inputFocused = true"
|
:aria-hidden="voiceMode"
|
||||||
@blur="inputFocused = false"
|
|
||||||
/>
|
/>
|
||||||
<div
|
<button
|
||||||
v-if="voiceHitVisible"
|
v-if="voiceMode"
|
||||||
class="voice-hit"
|
ref="holdRef"
|
||||||
|
class="voice-hold"
|
||||||
|
:class="{ active: voicePressing, cancel: willCancel }"
|
||||||
|
type="button"
|
||||||
|
:disabled="props.disabled || props.isGenerating"
|
||||||
@pointerdown="handleVoicePointerDown"
|
@pointerdown="handleVoicePointerDown"
|
||||||
@pointermove="handleVoicePointerMove"
|
|
||||||
@pointerup="handleVoicePointerUp"
|
|
||||||
@pointercancel="handleVoicePointerCancel"
|
|
||||||
@contextmenu.prevent
|
@contextmenu.prevent
|
||||||
/>
|
>
|
||||||
|
<t-icon name="voice-wave" size="small" />
|
||||||
|
<span v-text="voiceHoldLabel" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<div class="tools">
|
<div class="tools">
|
||||||
@@ -93,13 +86,49 @@
|
|||||||
<t-button
|
<t-button
|
||||||
class="send"
|
class="send"
|
||||||
type="button"
|
type="button"
|
||||||
size="extra-small"
|
size="small"
|
||||||
theme="danger"
|
theme="danger"
|
||||||
:disabled="props.disabled"
|
:disabled="props.disabled"
|
||||||
:content="props.stopText"
|
:content="props.stopText"
|
||||||
@click="emit('stop')"
|
@click="emit('stop')"
|
||||||
/>
|
>
|
||||||
|
<template #icon>
|
||||||
|
<t-icon name="stop" />
|
||||||
|
</template>
|
||||||
|
</t-button>
|
||||||
</slot>
|
</slot>
|
||||||
|
<template v-else-if="props.voiceEnabled && voiceMode">
|
||||||
|
<t-button
|
||||||
|
class="send voice-toggle"
|
||||||
|
type="button"
|
||||||
|
size="small"
|
||||||
|
theme="primary"
|
||||||
|
aria-label="切换到键盘输入"
|
||||||
|
:disabled="props.disabled || voicePressing || props.voiceState !== 'idle'"
|
||||||
|
content="输入"
|
||||||
|
@click="exitVoiceMode"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<t-icon name="keyboard-1" />
|
||||||
|
</template>
|
||||||
|
</t-button>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="props.voiceEnabled && !draft.trim()">
|
||||||
|
<t-button
|
||||||
|
class="send voice-toggle"
|
||||||
|
type="button"
|
||||||
|
size="small"
|
||||||
|
theme="primary"
|
||||||
|
aria-label="语音输入"
|
||||||
|
:disabled="props.disabled || props.voiceState !== 'idle'"
|
||||||
|
content="语音"
|
||||||
|
@click="enterVoiceMode"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<t-icon name="voice-wave" />
|
||||||
|
</template>
|
||||||
|
</t-button>
|
||||||
|
</template>
|
||||||
<slot
|
<slot
|
||||||
v-else
|
v-else
|
||||||
name="send"
|
name="send"
|
||||||
@@ -109,11 +138,15 @@
|
|||||||
<t-button
|
<t-button
|
||||||
class="send"
|
class="send"
|
||||||
type="submit"
|
type="submit"
|
||||||
size="extra-small"
|
size="small"
|
||||||
theme="primary"
|
theme="primary"
|
||||||
:disabled="props.disabled"
|
:disabled="props.disabled"
|
||||||
:content="sendButtonText"
|
:content="props.sendText"
|
||||||
/>
|
>
|
||||||
|
<template #icon>
|
||||||
|
<t-icon name="send-1" />
|
||||||
|
</template>
|
||||||
|
</t-button>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
</t-form>
|
</t-form>
|
||||||
@@ -121,7 +154,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, onBeforeUnmount, ref, useTemplateRef, watch } from "vue";
|
import { computed, nextTick, onBeforeUnmount, ref, useTemplateRef, watch } from "vue";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "AiChatComposer"
|
name: "AiChatComposer"
|
||||||
@@ -137,22 +170,18 @@ export interface Props {
|
|||||||
stopText?: string;
|
stopText?: string;
|
||||||
retryText?: string;
|
retryText?: string;
|
||||||
maxLength?: number;
|
maxLength?: number;
|
||||||
/** 是否启用长按输入框语音输入 */
|
/** 是否启用语音输入 */
|
||||||
voiceEnabled?: boolean;
|
voiceEnabled?: boolean;
|
||||||
/** 语音识别状态,由业务侧驱动 */
|
/** 语音识别状态,由业务侧驱动 */
|
||||||
voiceState?: "idle" | "listening" | "processing";
|
voiceState?: "idle" | "listening" | "processing";
|
||||||
/** 语音中间结果 */
|
/** 语音中间结果 */
|
||||||
voiceText?: string;
|
voiceText?: string;
|
||||||
/** 松开发送提示,同时作为按住时的发送按钮文案 */
|
/** 按住说话提示 */
|
||||||
|
voiceHoldText?: string;
|
||||||
|
/** 按住时的提示 */
|
||||||
voiceSendHint?: string;
|
voiceSendHint?: string;
|
||||||
/** 上滑到取消按钮时的提示 */
|
/** 移出按住按钮时的提示 */
|
||||||
voiceCancelHint?: string;
|
voiceCancelHint?: string;
|
||||||
/** 上滑到保留按钮时的提示 */
|
|
||||||
voiceKeepHint?: string;
|
|
||||||
/** 取消发送按钮文案 */
|
|
||||||
voiceCancelText?: string;
|
|
||||||
/** 保留识别按钮文案 */
|
|
||||||
voiceKeepText?: string;
|
|
||||||
/** 正在聆听提示 */
|
/** 正在聆听提示 */
|
||||||
voiceListeningText?: string;
|
voiceListeningText?: string;
|
||||||
/** 正在识别提示 */
|
/** 正在识别提示 */
|
||||||
@@ -171,11 +200,9 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
voiceEnabled: false,
|
voiceEnabled: false,
|
||||||
voiceState: "idle",
|
voiceState: "idle",
|
||||||
voiceText: "",
|
voiceText: "",
|
||||||
voiceSendHint: "松开发送",
|
voiceHoldText: "按住 说话",
|
||||||
voiceCancelHint: "松开取消",
|
voiceSendHint: "松开 发送",
|
||||||
voiceKeepHint: "松开保留",
|
voiceCancelHint: "松开 取消",
|
||||||
voiceCancelText: "取消发送",
|
|
||||||
voiceKeepText: "保留识别",
|
|
||||||
voiceListeningText: "正在听你说…",
|
voiceListeningText: "正在听你说…",
|
||||||
voiceProcessingText: "正在识别…"
|
voiceProcessingText: "正在识别…"
|
||||||
});
|
});
|
||||||
@@ -189,71 +216,55 @@ const emit = defineEmits<{
|
|||||||
"add-attachment": [];
|
"add-attachment": [];
|
||||||
"voice-start": [];
|
"voice-start": [];
|
||||||
"voice-stop": [];
|
"voice-stop": [];
|
||||||
"voice-keep": [];
|
|
||||||
"voice-cancel": [];
|
"voice-cancel": [];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
/** 长按触发语音的阈值,短按仍然聚焦输入 */
|
|
||||||
const VOICE_HOLD_DELAY = 300;
|
|
||||||
/** 未触发语音时,手指移动超过该距离视为滑动 */
|
|
||||||
const VOICE_MOVE_TOLERANCE = 12;
|
|
||||||
/** 按钮命中区域外扩,避免边缘难以对准;需小于按钮间距,防止两个按钮重叠 */
|
|
||||||
const VOICE_ACTION_HIT_PADDING = 4;
|
|
||||||
|
|
||||||
type VoiceAction = "cancel" | "keep" | "send";
|
|
||||||
|
|
||||||
const textareaRef = useTemplateRef<{ focus: () => void }>("textareaRef");
|
const textareaRef = useTemplateRef<{ focus: () => void }>("textareaRef");
|
||||||
const cancelActionRef = useTemplateRef<HTMLElement>("cancelActionRef");
|
const holdRef = useTemplateRef<HTMLElement>("holdRef");
|
||||||
const keepActionRef = useTemplateRef<HTMLElement>("keepActionRef");
|
const voiceMode = ref(false);
|
||||||
const inputFocused = ref(false);
|
|
||||||
const voicePressing = ref(false);
|
const voicePressing = ref(false);
|
||||||
const voiceTriggered = ref(false);
|
|
||||||
const willCancel = ref(false);
|
const willCancel = ref(false);
|
||||||
const willKeep = ref(false);
|
|
||||||
const voiceSessionActive = ref(false);
|
|
||||||
const voiceKeepPending = ref(false);
|
|
||||||
let voiceTimer: number | undefined;
|
|
||||||
let voiceStartY = 0;
|
|
||||||
let voicePointerId: number | undefined;
|
let voicePointerId: number | undefined;
|
||||||
|
|
||||||
/** 输入框为空且未聚焦时才接管长按;识别中保持覆盖层以持续接收指针事件 */
|
const voiceTranscript = computed(() => props.voiceText.trim());
|
||||||
const voiceHitVisible = computed(() => props.voiceEnabled
|
|
||||||
&& !props.disabled
|
|
||||||
&& !props.isGenerating
|
|
||||||
&& (voicePressing.value || (!draft.value.trim() && !inputFocused.value && props.voiceState === "idle")));
|
|
||||||
|
|
||||||
const voiceActive = computed(() => voicePressing.value && voiceTriggered.value);
|
const voiceHoldLabel = computed(() => {
|
||||||
|
|
||||||
const voiceActionsVisible = computed(() => voiceActive.value);
|
|
||||||
|
|
||||||
const voiceStatusText = computed(() => {
|
|
||||||
if (willCancel.value) {
|
if (willCancel.value) {
|
||||||
return props.voiceCancelHint;
|
return props.voiceCancelHint;
|
||||||
}
|
}
|
||||||
if (willKeep.value) {
|
if (props.voiceState === "processing") {
|
||||||
return props.voiceKeepHint;
|
return props.voiceProcessingText;
|
||||||
}
|
}
|
||||||
return props.voiceState === "processing" ? props.voiceProcessingText : props.voiceListeningText;
|
if (voicePressing.value) {
|
||||||
|
return props.voiceSendHint;
|
||||||
|
}
|
||||||
|
if (props.voiceState === "listening") {
|
||||||
|
return props.voiceListeningText;
|
||||||
|
}
|
||||||
|
return props.voiceHoldText;
|
||||||
});
|
});
|
||||||
|
|
||||||
const sendButtonText = computed(() => voiceActive.value ? props.voiceSendHint : props.sendText);
|
const voiceTranscriptHint = computed(() => {
|
||||||
|
if (voiceTranscript.value) {
|
||||||
/** ASR 结果直接写进输入框;取消后停止同步,保留后忽略调用方清空 voiceText 的动作 */
|
return "";
|
||||||
watch(() => props.voiceText, (text) => {
|
|
||||||
if (!voiceSessionActive.value) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (voiceKeepPending.value && !text) {
|
if (props.voiceState === "processing") {
|
||||||
return;
|
return props.voiceProcessingText;
|
||||||
}
|
}
|
||||||
draft.value = text;
|
if (voicePressing.value || props.voiceState === "listening") {
|
||||||
|
return props.voiceListeningText;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(() => props.voiceState, (state) => {
|
watch(() => props.voiceEnabled, (enabled) => {
|
||||||
if (state === "idle" && voiceSessionActive.value) {
|
if (enabled) {
|
||||||
voiceSessionActive.value = false;
|
return;
|
||||||
voiceKeepPending.value = false;
|
|
||||||
}
|
}
|
||||||
|
if (voicePressing.value) {
|
||||||
|
cancelVoice();
|
||||||
|
}
|
||||||
|
voiceMode.value = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
function startNewConversation(): void {
|
function startNewConversation(): void {
|
||||||
@@ -283,130 +294,94 @@ function submitMessage(): void {
|
|||||||
emit("send", message);
|
emit("send", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleVoicePointerDown(event: PointerEvent): void {
|
function enterVoiceMode(): void {
|
||||||
if (!props.voiceEnabled || props.disabled || props.isGenerating || props.voiceState !== "idle" || draft.value.trim()) {
|
if (!props.voiceEnabled || props.disabled || props.isGenerating || props.voiceState !== "idle" || draft.value.trim()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
voiceMode.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function exitVoiceMode(): void {
|
||||||
|
if (voicePressing.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
voiceMode.value = false;
|
||||||
|
nextTick(() => textareaRef.value?.focus());
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleVoicePointerDown(event: PointerEvent): void {
|
||||||
|
if (!props.voiceEnabled || !voiceMode.value || props.disabled || props.isGenerating || props.voiceState !== "idle" || voicePressing.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
voicePressing.value = true;
|
voicePressing.value = true;
|
||||||
voiceTriggered.value = false;
|
|
||||||
willCancel.value = false;
|
willCancel.value = false;
|
||||||
willKeep.value = false;
|
|
||||||
voiceSessionActive.value = false;
|
|
||||||
voiceKeepPending.value = false;
|
|
||||||
voiceStartY = event.clientY;
|
|
||||||
voicePointerId = event.pointerId;
|
voicePointerId = event.pointerId;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
try {
|
// 监听 window,手指移出按钮后仍能收到移动、释放和取消
|
||||||
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
window.addEventListener("pointermove", handleVoicePointerMove);
|
||||||
} catch {
|
window.addEventListener("pointerup", handleVoicePointerUp);
|
||||||
// 指针捕获失败时仍可依赖冒泡事件,忽略
|
window.addEventListener("pointercancel", handleVoicePointerCancel);
|
||||||
}
|
navigator.vibrate?.(15);
|
||||||
voiceTimer = window.setTimeout(() => {
|
emit("voice-start");
|
||||||
if (!voicePressing.value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
voiceTriggered.value = true;
|
|
||||||
voiceSessionActive.value = true;
|
|
||||||
voiceKeepPending.value = false;
|
|
||||||
draft.value = "";
|
|
||||||
navigator.vibrate?.(15);
|
|
||||||
emit("voice-start");
|
|
||||||
}, VOICE_HOLD_DELAY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleVoicePointerMove(event: PointerEvent): void {
|
function handleVoicePointerMove(event: PointerEvent): void {
|
||||||
if (!voicePressing.value || event.pointerId !== voicePointerId) {
|
if (!voicePressing.value || event.pointerId !== voicePointerId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!voiceTriggered.value) {
|
willCancel.value = !isPointInsideHold(event);
|
||||||
if (Math.abs(event.clientY - voiceStartY) > VOICE_MOVE_TOLERANCE) {
|
|
||||||
resetVoicePress();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const action = resolveVoiceAction(event);
|
|
||||||
willCancel.value = action === "cancel";
|
|
||||||
willKeep.value = action === "keep";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveVoiceAction(event: PointerEvent): VoiceAction {
|
function isPointInsideHold(event: PointerEvent): boolean {
|
||||||
if (isPointInsideAction(event, cancelActionRef.value)) {
|
const element = holdRef.value;
|
||||||
return "cancel";
|
|
||||||
}
|
|
||||||
if (isPointInsideAction(event, keepActionRef.value)) {
|
|
||||||
return "keep";
|
|
||||||
}
|
|
||||||
return "send";
|
|
||||||
}
|
|
||||||
|
|
||||||
function isPointInsideAction(event: PointerEvent, element: HTMLElement | null): boolean {
|
|
||||||
if (!element) {
|
if (!element) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const rect = element.getBoundingClientRect();
|
const rect = element.getBoundingClientRect();
|
||||||
return event.clientX >= rect.left - VOICE_ACTION_HIT_PADDING
|
return event.clientX >= rect.left
|
||||||
&& event.clientX <= rect.right + VOICE_ACTION_HIT_PADDING
|
&& event.clientX <= rect.right
|
||||||
&& event.clientY >= rect.top - VOICE_ACTION_HIT_PADDING
|
&& event.clientY >= rect.top
|
||||||
&& event.clientY <= rect.bottom + VOICE_ACTION_HIT_PADDING;
|
&& event.clientY <= rect.bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleVoicePointerUp(event: PointerEvent): void {
|
function handleVoicePointerUp(event: PointerEvent): void {
|
||||||
if (!voicePressing.value || event.pointerId !== voicePointerId) {
|
if (!voicePressing.value || event.pointerId !== voicePointerId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const triggered = voiceTriggered.value;
|
if (!isPointInsideHold(event)) {
|
||||||
const action = resolveVoiceAction(event);
|
|
||||||
resetVoicePress();
|
|
||||||
if (!triggered) {
|
|
||||||
textareaRef.value?.focus();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (action === "cancel") {
|
|
||||||
cancelVoice();
|
cancelVoice();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (action === "keep") {
|
resetVoicePress();
|
||||||
voiceKeepPending.value = true;
|
|
||||||
emit("voice-keep");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emit("voice-stop");
|
emit("voice-stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleVoicePointerCancel(): void {
|
function handleVoicePointerCancel(event: PointerEvent): void {
|
||||||
if (!voicePressing.value) {
|
if (!voicePressing.value || event.pointerId !== voicePointerId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const triggered = voiceTriggered.value;
|
cancelVoice();
|
||||||
resetVoicePress();
|
|
||||||
if (triggered) {
|
|
||||||
cancelVoice();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelVoice(): void {
|
function cancelVoice(): void {
|
||||||
voiceSessionActive.value = false;
|
resetVoicePress();
|
||||||
voiceKeepPending.value = false;
|
|
||||||
draft.value = "";
|
|
||||||
emit("voice-cancel");
|
emit("voice-cancel");
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetVoicePress(): void {
|
function resetVoicePress(): void {
|
||||||
if (voiceTimer !== undefined) {
|
window.removeEventListener("pointermove", handleVoicePointerMove);
|
||||||
window.clearTimeout(voiceTimer);
|
window.removeEventListener("pointerup", handleVoicePointerUp);
|
||||||
voiceTimer = undefined;
|
window.removeEventListener("pointercancel", handleVoicePointerCancel);
|
||||||
}
|
|
||||||
voicePressing.value = false;
|
voicePressing.value = false;
|
||||||
voiceTriggered.value = false;
|
|
||||||
willCancel.value = false;
|
willCancel.value = false;
|
||||||
willKeep.value = false;
|
|
||||||
voicePointerId = undefined;
|
voicePointerId = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
if (voiceTimer !== undefined) {
|
if (voicePressing.value) {
|
||||||
window.clearTimeout(voiceTimer);
|
emit("voice-cancel");
|
||||||
}
|
}
|
||||||
|
resetVoicePress();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -453,9 +428,12 @@ onBeforeUnmount(() => {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
.input-wrap {
|
.input-wrap {
|
||||||
|
gap: .375rem;
|
||||||
|
display: flex;
|
||||||
position: relative;
|
position: relative;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
@@ -463,115 +441,118 @@ onBeforeUnmount(() => {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 0 .25rem;
|
padding: 0 .25rem;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|
||||||
|
&.voice-input-hidden {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.voice-hit {
|
.voice-transcript {
|
||||||
inset: 0;
|
|
||||||
z-index: 1;
|
|
||||||
position: absolute;
|
|
||||||
touch-action: none;
|
|
||||||
-webkit-tap-highlight-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voice-actions {
|
|
||||||
gap: .375rem;
|
|
||||||
left: 50%;
|
left: 50%;
|
||||||
|
gap: .5rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: .5rem;
|
padding: .5rem .75rem;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
bottom: calc(100% + .5rem);
|
bottom: calc(100% + .5rem);
|
||||||
user-select: none;
|
align-items: center;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
border: 1px solid var(--td-brand-color);
|
border: 1px solid var(--td-brand-color);
|
||||||
background: var(--td-bg-color-container);
|
background: var(--td-bg-color-container);
|
||||||
box-shadow: 0 .5rem 1.5rem rgba(15, 23, 42, .16);
|
box-shadow: 0 .5rem 1.5rem rgba(15, 23, 42, .16);
|
||||||
animation: voice-actions-in .16s ease-out;
|
animation: voice-transcript-in .16s ease-out;
|
||||||
border-radius: 1rem;
|
border-radius: 1rem;
|
||||||
flex-direction: column;
|
|
||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
.voice-status {
|
.voice-wave {
|
||||||
gap: .375rem;
|
gap: .1875rem;
|
||||||
display: flex;
|
height: 1rem;
|
||||||
min-height: 1.25rem;
|
display: flex;
|
||||||
color: var(--td-text-color-secondary);
|
flex: none;
|
||||||
font-size: .75rem;
|
align-items: center;
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
span {
|
||||||
|
width: .125rem;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: .125rem;
|
||||||
|
background: var(--td-brand-color);
|
||||||
|
animation: voice-wave .9s ease-in-out infinite;
|
||||||
|
animation-delay: calc(var(--i) * .1s);
|
||||||
|
transform: scaleY(.3);
|
||||||
|
transform-origin: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.voice-text,
|
||||||
|
.voice-placeholder {
|
||||||
|
margin: 0;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voice-text {
|
||||||
|
display: -webkit-box;
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--td-text-color-primary);
|
||||||
|
font-size: .875rem;
|
||||||
|
line-height: 1.4;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voice-placeholder {
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
font-size: .75rem;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.voice-hold {
|
||||||
|
inset: 0;
|
||||||
|
gap: .375rem;
|
||||||
|
z-index: 1;
|
||||||
|
display: flex;
|
||||||
|
padding: 0 .75rem;
|
||||||
|
position: absolute;
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
font-size: .875rem;
|
||||||
|
font-weight: 500;
|
||||||
|
transition: color .15s, border-color .15s;
|
||||||
|
border: 0;
|
||||||
|
border-bottom: 1px solid var(--td-component-border);
|
||||||
|
background: transparent;
|
||||||
|
border-radius: 0;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
touch-action: none;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
border-bottom-color: var(--td-brand-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.voice-wave {
|
&.cancel {
|
||||||
gap: .1875rem;
|
color: var(--td-error-color);
|
||||||
height: .875rem;
|
border-bottom-color: var(--td-error-color);
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
span {
|
|
||||||
width: .125rem;
|
|
||||||
height: 30%;
|
|
||||||
border-radius: .125rem;
|
|
||||||
background: var(--td-brand-color);
|
|
||||||
animation: voice-wave .9s ease-in-out infinite;
|
|
||||||
animation-delay: calc(var(--i) * .1s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.voice-status-text {
|
&:disabled {
|
||||||
min-width: 0;
|
opacity: .55;
|
||||||
overflow: hidden;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voice-buttons {
|
|
||||||
gap: .5rem;
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.voice-action {
|
|
||||||
gap: .25rem;
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
padding: .4375rem .5rem;
|
|
||||||
font-size: .75rem;
|
|
||||||
transition: color .15s, background .15s, border-color .15s, transform .15s;
|
|
||||||
border: 1px solid var(--td-component-border);
|
|
||||||
border-radius: .625rem;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
|
|
||||||
&.cancel {
|
|
||||||
color: var(--td-error-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.keep {
|
|
||||||
color: var(--td-brand-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.active {
|
|
||||||
color: #fff;
|
|
||||||
transform: translateY(-.0625rem);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.cancel.active {
|
|
||||||
border-color: var(--td-error-color);
|
|
||||||
background: var(--td-error-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.keep.active {
|
|
||||||
border-color: var(--td-brand-color);
|
|
||||||
background: var(--td-brand-color);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.actions {
|
.actions {
|
||||||
--td-button-border-radius: .75rem;
|
--td-button-border-radius: 1rem;
|
||||||
|
|
||||||
gap: .5rem;
|
gap: .5rem;
|
||||||
|
min-height: 2rem;
|
||||||
margin-top: .375rem;
|
margin-top: .375rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -582,44 +563,53 @@ onBeforeUnmount(() => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.send {
|
|
||||||
padding: 0 1rem;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.voice-active .form {
|
&.voice-active .form {
|
||||||
border-color: var(--td-brand-color);
|
border-color: var(--td-brand-color);
|
||||||
animation: voice-breathe 1.8s ease-in-out infinite;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes voice-wave {
|
&::after {
|
||||||
0%,
|
content: "";
|
||||||
100% {
|
inset: -.125rem;
|
||||||
height: 25%;
|
border: 1px solid var(--td-brand-color);
|
||||||
opacity: .5;
|
position: absolute;
|
||||||
}
|
animation: voice-breathe 1s ease-in-out 0s infinite;
|
||||||
|
will-change: transform, opacity;
|
||||||
50% {
|
border-radius: inherit;
|
||||||
height: 100%;
|
pointer-events: none;
|
||||||
opacity: 1;
|
transform-origin: center;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes voice-breathe {
|
@keyframes voice-breathe {
|
||||||
0%,
|
0%,
|
||||||
100% {
|
100% {
|
||||||
box-shadow: 0 0 0 .125rem var(--td-brand-color-light, rgba(0, 82, 217, .16)), 0 .5rem 1.5rem rgba(15, 23, 42, .12);
|
opacity: .6;
|
||||||
|
transform: scaleX(1) scaleY(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
50% {
|
50% {
|
||||||
box-shadow: 0 0 0 .375rem var(--td-brand-color-light, rgba(0, 82, 217, .16)), 0 .5rem 1.5rem rgba(15, 23, 42, .12);
|
opacity: .2;
|
||||||
|
transform: scaleX(1.02) scaleY(1.08);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes voice-actions-in {
|
@keyframes voice-wave {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
opacity: .5;
|
||||||
|
transform: scaleY(.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scaleY(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes voice-transcript-in {
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
@@ -629,14 +619,6 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-reduced-motion: reduce) {
|
|
||||||
.composer.voice-active .form,
|
|
||||||
.voice-actions,
|
|
||||||
.voice-actions .voice-wave span {
|
|
||||||
animation: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:global(html.theme-dark) {
|
:global(html.theme-dark) {
|
||||||
.error-bar {
|
.error-bar {
|
||||||
color: var(--ai-chat-error-color-dark, #fda29b);
|
color: var(--ai-chat-error-color-dark, #fda29b);
|
||||||
|
|||||||
Reference in New Issue
Block a user