( payload: TranscribeWorkflowPayload, )
| 51 | } |
| 52 | |
| 53 | export async function transcribeVideoWorkflow( |
| 54 | payload: TranscribeWorkflowPayload, |
| 55 | ) { |
| 56 | "use workflow"; |
| 57 | |
| 58 | const { videoId, userId, aiGenerationEnabled } = payload; |
| 59 | |
| 60 | const videoData = await validateVideo(videoId); |
| 61 | |
| 62 | if (videoData.transcriptionDisabled) { |
| 63 | await markSkipped(videoId); |
| 64 | return { success: true, message: "Transcription disabled - skipped" }; |
| 65 | } |
| 66 | |
| 67 | try { |
| 68 | const audioUrl = await extractAudio(videoId, userId, videoData.video); |
| 69 | |
| 70 | if (!audioUrl) { |
| 71 | await markNoAudio(videoId); |
| 72 | return { |
| 73 | success: true, |
| 74 | message: "Video has no audio track - skipped transcription", |
| 75 | }; |
| 76 | } |
| 77 | |
| 78 | const [transcription] = await Promise.all([ |
| 79 | transcribeWithDeepgram(audioUrl, videoData.aiGenerationLanguage), |
| 80 | ]); |
| 81 | |
| 82 | await saveTranscription(videoId, userId, videoData.video, transcription); |
| 83 | } catch (error) { |
| 84 | await markError(videoId); |
| 85 | await cleanupTempAudio(videoId, userId, videoData.video); |
| 86 | throw error; |
| 87 | } |
| 88 | |
| 89 | await cleanupTempAudio(videoId, userId, videoData.video); |
| 90 | |
| 91 | if (aiGenerationEnabled) { |
| 92 | await queueAiGeneration(videoId, userId); |
| 93 | } |
| 94 | |
| 95 | return { success: true, message: "Transcription completed successfully" }; |
| 96 | } |
| 97 | |
| 98 | async function validateVideo(videoId: string): Promise<VideoData> { |
| 99 | "use step"; |
nothing calls this directly
no test coverage detected