mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-02 20:58:12 +00:00
4.7.1-alpha2 (#1153)
Co-authored-by: UUUUnotfound <31206589+UUUUnotfound@users.noreply.github.com> Co-authored-by: Hexiao Zhang <731931282qq@gmail.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
@@ -12,7 +12,6 @@ import { MongoTTSBuffer } from '@fastgpt/service/common/buffer/tts/schema';
|
||||
/*
|
||||
1. get tts from chatItem store
|
||||
2. get tts from ai
|
||||
3. save tts to chatItem store if chatItemId is provided
|
||||
4. push bill
|
||||
*/
|
||||
|
||||
@@ -34,6 +33,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error('voice not found');
|
||||
}
|
||||
|
||||
/* get audio from buffer */
|
||||
const ttsBuffer = await MongoTTSBuffer.findOne(
|
||||
{
|
||||
bufferId: voiceData.bufferId,
|
||||
@@ -46,6 +46,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
return res.end(new Uint8Array(ttsBuffer.buffer.buffer));
|
||||
}
|
||||
|
||||
/* request audio */
|
||||
await text2Speech({
|
||||
res,
|
||||
input,
|
||||
@@ -54,6 +55,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
speed: ttsConfig.speed,
|
||||
onSuccess: async ({ model, buffer }) => {
|
||||
try {
|
||||
/* bill */
|
||||
pushAudioSpeechUsage({
|
||||
model: model,
|
||||
charsLength: input.length,
|
||||
@@ -62,6 +64,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
source: authType2UsageSource({ authType })
|
||||
});
|
||||
|
||||
/* create buffer */
|
||||
await MongoTTSBuffer.create({
|
||||
bufferId: voiceData.bufferId,
|
||||
text: JSON.stringify({ text: input, speed: ttsConfig.speed }),
|
||||
|
@@ -7,6 +7,8 @@ import fs from 'fs';
|
||||
import { getAIApi } from '@fastgpt/service/core/ai/config';
|
||||
import { pushWhisperUsage } from '@/service/support/wallet/usage/push';
|
||||
import { authChatCert } from '@/service/support/permission/auth/chat';
|
||||
import { MongoApp } from '@fastgpt/service/core/app/schema';
|
||||
import { getGuideModule, splitGuideModule } from '@fastgpt/global/core/module/utils';
|
||||
|
||||
const upload = getUploadModel({
|
||||
maxSize: 2
|
||||
@@ -18,8 +20,9 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
try {
|
||||
const {
|
||||
file,
|
||||
data: { duration, teamId: spaceTeamId, teamToken }
|
||||
data: { appId, duration, teamId: spaceTeamId, teamToken }
|
||||
} = await upload.doUpload<{
|
||||
appId: string;
|
||||
duration: number;
|
||||
shareId?: string;
|
||||
teamId?: string;
|
||||
@@ -31,8 +34,6 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
|
||||
filePaths = [file.path];
|
||||
|
||||
const { teamId, tmbId } = await authChatCert({ req, authToken: true });
|
||||
|
||||
if (!global.whisperModel) {
|
||||
throw new Error('whisper model not found');
|
||||
}
|
||||
@@ -41,6 +42,18 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
throw new Error('file not found');
|
||||
}
|
||||
|
||||
// auth role
|
||||
const { teamId, tmbId } = await authChatCert({ req, authToken: true });
|
||||
// auth app
|
||||
const app = await MongoApp.findById(appId, 'modules').lean();
|
||||
if (!app) {
|
||||
throw new Error('app not found');
|
||||
}
|
||||
const { whisperConfig } = splitGuideModule(getGuideModule(app?.modules));
|
||||
if (!whisperConfig?.open) {
|
||||
throw new Error('Whisper is not open in the app');
|
||||
}
|
||||
|
||||
const ai = getAIApi();
|
||||
|
||||
const result = await ai.audio.transcriptions.create({
|
||||
|
Reference in New Issue
Block a user