From 84223d4c703e942f6965b0d10067cae92d1b3c6a Mon Sep 17 00:00:00 2001 From: xjs Date: Tue, 10 Jun 2025 13:51:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20android=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/MainArea/index.tsx | 14 ++-- src/components/AntechamberFile/index.tsx | 3 +- .../Provider/RealtimeClientProvider.tsx | 24 +++--- src/hooks/useAudioTest.ts | 75 +++++++++++++++++++ 4 files changed, 97 insertions(+), 19 deletions(-) create mode 100644 src/hooks/useAudioTest.ts diff --git a/src/app/MainArea/index.tsx b/src/app/MainArea/index.tsx index 9e3cf14..d86f75d 100644 --- a/src/app/MainArea/index.tsx +++ b/src/app/MainArea/index.tsx @@ -6,20 +6,20 @@ import { RealtimeClientProvider, } from "@/components/Provider/RealtimeClientProvider"; import { ReportProvider } from "@/components/Provider/ReportResolveProvider"; -import { RealtimeUtils } from "@coze/realtime-api"; +// import { RealtimeUtils } from "@coze/realtime-api"; import { useLocation } from "react-router-dom"; function MainContent() { const { isConnected, handleDisconnect } = useContext(RealtimeClientContext); const location = useLocation(); - const handlePromise = async() => { - await RealtimeUtils.checkDevicePermission(false); - } + // const handlePromise = async() => { + // await RealtimeUtils.checkDevicePermission(false); + // } - useEffect(() => { - handlePromise(); - }, []); + // useEffect(() => { + // handlePromise(); + // }, []); useEffect(() => { if (isConnected) { diff --git a/src/components/AntechamberFile/index.tsx b/src/components/AntechamberFile/index.tsx index 1a35c8c..b59e4af 100644 --- a/src/components/AntechamberFile/index.tsx +++ b/src/components/AntechamberFile/index.tsx @@ -39,8 +39,9 @@ export default function AntechamberFile({handleLoading}:Props) { handleConnect({ fileInfo: {type: resp.type,url: resp.url,tableName: resp.tableName,provinceName: resp.provinceName,subjectClaim: resp.subjectClaim}, + }).then(() => { + setHasHandledReport(true); }); - setHasHandledReport(true); }; diff --git a/src/components/Provider/RealtimeClientProvider.tsx b/src/components/Provider/RealtimeClientProvider.tsx index 7b6cf74..31383a0 100644 --- a/src/components/Provider/RealtimeClientProvider.tsx +++ b/src/components/Provider/RealtimeClientProvider.tsx @@ -105,17 +105,7 @@ export const RealtimeClientProvider = ({ initMessage?: string; fileInfo?: FileInfo; }) => { - const perm = await RealtimeUtils.checkDevicePermission(false); - const device = await RealtimeUtils.getAudioDevices(); - if (!perm.audio) { - toast({ title: "连接错误", description: "需要麦克风访问权限" }); - throw new Error("需要麦克风访问权限"); - } - if (device.audioInputs.length === 0) { - toast({ title: "连接错误", description: "没有麦克风设备" }); - throw new Error("没有麦克风设备"); - } const client = new RealtimeClient({ accessToken: token, @@ -125,7 +115,7 @@ export const RealtimeClientProvider = ({ allowPersonalAccessTokenInBrowser: true, suppressStationaryNoise: true, suppressNonStationaryNoise: true, - debug: true, + debug: false, }); clientRef.current = client; @@ -149,6 +139,18 @@ export const RealtimeClientProvider = ({ connectingLockRef.current = false; return; } + const perm = await RealtimeUtils.checkDevicePermission(false); + const device = await RealtimeUtils.getAudioDevices(); + if (!perm.audio) { + toast({ title: "连接错误", description: "需要麦克风访问权限" }); + return; + // throw new Error("需要麦克风访问权限"); + } + if (device.audioInputs.length === 0) { + toast({ title: "连接错误", description: "没有麦克风设备" }); + return; + // throw new Error("没有麦克风设备"); + } try { if (!clientRef.current) { diff --git a/src/hooks/useAudioTest.ts b/src/hooks/useAudioTest.ts new file mode 100644 index 0000000..adda35b --- /dev/null +++ b/src/hooks/useAudioTest.ts @@ -0,0 +1,75 @@ +import { useEffect, useRef } from 'react'; + +export function useTtsPlayer() { + const audioRef = useRef(null); + + // 第一次挂载时,创建一个隐藏的