mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 02:28:30 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Yansong Zhang <916125788@qq.com>
38 lines
987 B
TypeScript
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)
|
|
}
|