dify/web/app/components/base/voice-input/api.ts
yyh ab521c4cfd
refactor(chat): modernize speech-to-text pipeline (#38653)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Yansong Zhang <916125788@qq.com>
2026-07-13 04:21:29 +00:00

38 lines
987 B
TypeScript

import type { SpeechToTextTarget } from './types'
import { audioToText } from '@/service/share'
export async function transcribeAudio(
target: SpeechToTextTarget,
file: File,
signal?: AbortSignal,
): Promise<{ text: string }> {
if (target.type === 'agent' || target.type === 'consoleApp') {
const { consoleClient } = await import('@/service/client')
if (target.type === 'agent') {
return consoleClient.agent.byAgentId.audioToText.post(
{
body: {
draft_type: target.draftType,
file,
},
params: {
agent_id: target.agentId,
},
},
{ signal },
)
}
return consoleClient.apps.byAppId.audioToText.post(
{
body: { file },
params: { app_id: target.appId },
},
{ signal },
)
}
const formData = new FormData()
formData.append('file', file)
return audioToText(target.appSourceType, target.appId, formData, signal)
}