From 1b8b11239c92ba4bb52af335cb8492f4ca58e248 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Mon, 9 Dec 2024 21:27:07 +0800 Subject: [PATCH] perf: speech check (#3351) * perf: speech check * perf: version --- projects/app/package.json | 2 +- .../src/pages/api/v1/audio/transcriptions.ts | 17 +++++++++++++---- .../app/src/pages/price/components/Points.tsx | 2 +- projects/app/src/web/common/utils/voice.ts | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/projects/app/package.json b/projects/app/package.json index 5d378119a5d6..bc6ba05be08a 100644 --- a/projects/app/package.json +++ b/projects/app/package.json @@ -1,6 +1,6 @@ { "name": "app", - "version": "4.8.14", + "version": "4.8.15", "private": false, "scripts": { "dev": "next dev", diff --git a/projects/app/src/pages/api/v1/audio/transcriptions.ts b/projects/app/src/pages/api/v1/audio/transcriptions.ts index 3021f6a9b189..29d3fcf66bb1 100644 --- a/projects/app/src/pages/api/v1/audio/transcriptions.ts +++ b/projects/app/src/pages/api/v1/audio/transcriptions.ts @@ -8,16 +8,17 @@ import { authChatCrud } from '@/service/support/permission/auth/chat'; import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat'; import { NextAPI } from '@/service/middleware/entry'; import { aiTranscriptions } from '@fastgpt/service/core/ai/audio/transcriptions'; +import { useReqFrequencyLimit } from '@fastgpt/service/common/middle/reqFrequencyLimit'; const upload = getUploadModel({ - maxSize: 20 + maxSize: 5 }); async function handler(req: NextApiRequest, res: NextApiResponse) { let filePaths: string[] = []; try { - const { + let { file, data: { appId, duration, shareId, outLinkUid, teamId: spaceTeamId, teamToken } } = await upload.doUpload< @@ -42,9 +43,17 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { if (!file) { throw new Error('file not found'); } + if (duration === undefined) { + throw new Error('duration not found'); + } + duration = duration < 1 ? 1 : duration; // auth role - const { teamId, tmbId } = await authChatCrud({ req, authToken: true, ...req.body }); + const { teamId, tmbId } = await authChatCrud({ + req, + authToken: true, + ...req.body + }); // auth app // const app = await MongoApp.findById(appId, 'modules').lean(); @@ -80,7 +89,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { removeFilesByPaths(filePaths); } -export default NextAPI(handler); +export default NextAPI(useReqFrequencyLimit(1, 2), handler); export const config = { api: { diff --git a/projects/app/src/pages/price/components/Points.tsx b/projects/app/src/pages/price/components/Points.tsx index b412b8b8cad0..87e84dd51027 100644 --- a/projects/app/src/pages/price/components/Points.tsx +++ b/projects/app/src/pages/price/components/Points.tsx @@ -141,7 +141,7 @@ export const AiPointsTable = () => { {whisperModel?.charsPointsPrice + t('common:support.wallet.subscription.point') + - ' / 1000' + + ' / 60' + t('common:unit.minute')} diff --git a/projects/app/src/web/common/utils/voice.ts b/projects/app/src/web/common/utils/voice.ts index 572a1c8c5f37..9b06e2bccf55 100644 --- a/projects/app/src/web/common/utils/voice.ts +++ b/projects/app/src/web/common/utils/voice.ts @@ -103,7 +103,7 @@ export const useAudioPlay = ( const cancelAudio = useCallback(() => { try { window.speechSynthesis?.cancel(); - audioController.current.abort(''); + !audioController.current.signal.aborted && audioController.current.abort(); } catch (error) {} if (audioRef.current) { audioRef.current.pause();