Commit 2533c39e by 李伟康

feat(chat): 添加语音输入功能并优化按钮样式

- 在聊天输入区域添加语音转文字功能
- 实现麦克风图标按钮组件
- 集成 js-audio-recorder 进行录音处理
- 添加权限获取和错误提示机制
- 优化 ActionButton 组件样式和尺寸配置
- 调整聊天底部布局结构
- 添加圆形图标容器样式支持
1 parent f43ec02b
......@@ -41,5 +41,13 @@
.action-btn.action-btn-destructive {
@apply text-text-destructive bg-state-destructive-hover
}
.action-btn.block-btn{
width: 32px;
height: 32px;
flex-shrink: 0;
border-radius: 100%;
overflow: hidden;
background-color: #fff;
box-shadow: 0px 2px 12px 0px rgba(44, 102, 247, 0.1);
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ enum ActionButtonState {
}
const actionButtonVariants = cva(
'action-btn',
'action-btn block-btn',
{
variants: {
size: {
......
import { FileContextProvider } from '@/app/components/base/file-uploader/store'
import InputWrapper from './wrapper'
import { VoiceInputProvider, MessageProvider,TextAreaHeightProvider } from '../../context'
import { VoiceInputProvider, MessageProvider, TextAreaHeightProvider } from '../../context'
const ChatInputAreaWrapper = () => {
return (
<FileContextProvider>
......
......@@ -6,7 +6,7 @@ import { useFileOperation } from '../../hooks'
import { useMessageContext, useTextAreaHeightContext } from '@/app/components/base/chat/chat/footer/context'
import s from './wrapper.module.scss'
import { useChatRespondingContext } from '@/app/components/base/chat/chat-with-history/context'
import SpeechToText from '../operation/speech-to-text'
const TextInput: React.FC<{
children: React.ReactNode
}> = React.memo(({ children }) => {
......@@ -77,6 +77,7 @@ const TextInput: React.FC<{
return (
// <div ref={wrapperRef} className="flex items-center justify-between">
<div ref={wrapperRef} className="flex items-center justify-between h-full">
<SpeechToText />
<div className="relative flex w-full grow items-center h-full">
<div
ref={textValueRef}
......
......@@ -5,23 +5,45 @@ import ActionButton from '@/app/components/base/action-button'
import { RiMicLine } from '@remixicon/react'
import Recorder from 'js-audio-recorder'
import { useVoiceInputContext } from '../../context'
import { useChatConfigContext } from '../../../../chat-with-history/context/chat-config-context'
const SpeechToText: FC = () => {
const { t } = useTranslation()
const { notify } = useToastContext()
// const { speech_to_text } = useChatConfigContext()
// const speechToTextConfig = speech_to_text
const { setShowVoiceInput } = useVoiceInputContext()
const handleShowVoiceInput = useCallback(() => {
;(Recorder as any).getPermission().then(
(Recorder as any).getPermission().then(
() => setShowVoiceInput(true),
() => notify({ type: 'error', message: t('common.voiceInput.notAllow') }),
)
}, [t, notify])
// if (!speechToTextConfig?.enabled) return null
return (
<ActionButton size="l" onClick={handleShowVoiceInput}>
<RiMicLine className="h-5 w-5" />
{/* <ActionButton size="l" onClick={handleShowVoiceInput}> */}
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_452_6113)">
<path
d="M7.99992 14.6667C11.6819 14.6667 14.6666 11.682 14.6666 8.00004C14.6666 4.31804 11.6819 1.33337 7.99992 1.33337C4.31792 1.33337 1.33325 4.31804 1.33325 8.00004C1.33325 11.682 4.31792 14.6667 7.99992 14.6667Z"
stroke="#292D33"
stroke-width="1.3"
stroke-linejoin="round"
/>
<path
d="M5.66667 8.63326C5.84348 8.63326 6.01305 8.56302 6.13807 8.438C6.2631 8.31297 6.33333 8.1434 6.33333 7.96659C6.33333 7.78978 6.2631 7.62021 6.13807 7.49519C6.01305 7.37016 5.84348 7.29993 5.66667 7.29993C5.48986 7.29993 5.32029 7.37016 5.19526 7.49519C5.07024 7.62021 5 7.78978 5 7.96659C5 8.1434 5.07024 8.31297 5.19526 8.438C5.32029 8.56302 5.48986 8.63326 5.66667 8.63326Z"
fill="#292D33"
/>
<path
d="M7.31665 9.61663C7.53361 9.40016 7.70567 9.14296 7.82293 8.8598C7.9402 8.57664 8.00037 8.27311 7.99998 7.96663C8.00037 7.66015 7.9402 7.35661 7.82293 7.07345C7.70567 6.79029 7.53361 6.53309 7.31665 6.31663M8.96665 11.2663C9.40057 10.8334 9.74468 10.319 9.97922 9.75264C10.2138 9.18633 10.3341 8.57925 10.3333 7.96629C10.3333 6.67763 9.81098 5.51096 8.96665 4.66663"
stroke="#292D33"
stroke-width="1.3"
stroke-linecap="round"
stroke-linejoin="round"
/>
</g>
<defs>
<clipPath id="clip0_452_6113">
<rect width="16" height="16" fill="white" />
</clipPath>
</defs>
</svg>
</ActionButton>
)
}
......
.icon-block{
box-shadow: 0px 2px 12px 0px rgba(44, 102, 247, 0.1);
width: 32px;
height: 32px;
border-radius: 50%;
background-color: #fff;
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ const Voice: FC = () => {
setQuery(text)
requestAnimationFrame(handleTextareaResize)
}, [])
if (!showVoiceInput) return null
// if (!showVoiceInput) return null
setQuery('')
return <VoiceInput onCancel={() => setShowVoiceInput(false)} onConverted={onConverted} />
}
......
......@@ -6,7 +6,6 @@ import s from './index.module.scss'
import { useStore } from '@/app/components/app/store'
import NextScene from './components/nextScene'
import AssessmentComplete from './components/assessmentComplete'
import SpeechToText from './components/operation/speech-to-text'
type FooterProps = {
isMobile?: boolean
chatFooterRef: React.RefObject<HTMLDivElement>
......@@ -23,7 +22,7 @@ const Footer: FC<FooterProps> = ({ isMobile, chatFooterRef, chatFooterInnerRef }
ref={chatFooterRef}>
{/* 配置加载器 */}
<ConfigLoader />
<SpeechToText />
<div
ref={chatFooterInnerRef}
className={cn('relative', `mx-auto w-full max-w-[800px] ${isMobile ? 'px-2' : 'px-4'}`)}>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!