Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add logging to audio enhancement and transcription

Richie McIlroy5e05c0c07e65
diff --git a/apps/web/lib/audio-enhance.ts b/apps/web/lib/audio-enhance.ts
index 01a56a8bc..981202524 100644
--- a/apps/web/lib/audio-enhance.ts
+++ b/apps/web/lib/audio-enhance.ts
@@ -16,6 +16,8 @@ export function isAudioEnhancementConfigured(): boolean {
}
export async function enhanceAudioFromUrl(audioUrl: string): Promise<Buffer> {
+ console.log("[audio-enhance] Starting audio enhancement");
+
const apiToken = serverEnv().REPLICATE_API_TOKEN;
if (!apiToken) {
throw new Error("REPLICATE_API_TOKEN is not configured");
@@ -29,6 +31,8 @@ export async function enhanceAudioFromUrl(audioUrl: string): Promise<Buffer> {
auth: apiToken,
});
+ console.log("[audio-enhance] Creating Replicate prediction...");
+
const prediction = await replicate.predictions.create({
version: "93266a7e7f5805fb79bcf213b1a4e0ef2e45aff3c06eefd96c59e850c87fd6a2",
input: {
@@ -36,6 +40,8 @@ export async function enhanceAudioFromUrl(audioUrl: string): Promise<Buffer> {
},
});
+ console.log(`[audio-enhance] Prediction created: ${prediction.id}`);
+
let result = prediction;
let attempts = 0;
@@ -62,13 +68,23 @@ export async function enhanceAudioFromUrl(audioUrl: string): Promise<Buffer> {
throw new Error("Replicate enhancement timed out");
}
+ console.log(
+ `[audio-enhance] Replicate completed after ${attempts} poll attempts`,
+ );
+
const output = result.output as string[] | undefined;
const enhancedAudioUrl = output?.[0];
if (!enhancedAudioUrl) {
throw new Error("No output received from Replicate");
}
+ console.log("[audio-enhance] Converting WAV to MP3 via media server...");
+
const mp3Buffer = await convertAudioToMp3ViaMediaServer(enhancedAudioUrl);
+ console.log(
+ `[audio-enhance] Conversion complete, buffer size: ${mp3Buffer.length} bytes`,
+ );
+
return mp3Buffer;
}
diff --git a/apps/web/workflows/transcribe.ts b/apps/web/workflows/transcribe.ts
index 75d8960ae..fbf91ea00 100644
--- a/apps/web/workflows/transcribe.ts
+++ b/apps/web/workflows/transcribe.ts
@@ -63,8 +63,12 @@ export async function transcribeVideoWorkflow(
};
}
- const shouldEnhanceAudio =
- videoData.isOwnerPro && isAudioEnhancementConfigured();
+ const enhancementConfigured = isAudioEnhancementConfigured();
+ const shouldEnhanceAudio = videoData.isOwnerPro && enhancementConfigured;
+
+ console.log(
+ `[transcribe] Audio enhancement check: isOwnerPro=${videoData.isOwnerPro}, configured=${enhancementConfigured}, shouldEnhance=${shouldEnhanceAudio}`,
+ );
if (shouldEnhanceAudio) {
await markEnhancedAudioProcessing(videoId);
@@ -337,8 +341,13 @@ async function enhanceAndSaveAudio(
): Promise<void> {
"use step";
+ console.log(`[transcribe] Starting audio enhancement for video ${videoId}`);
+
try {
const enhancedBuffer = await enhanceAudioFromUrl(audioUrl);
+ console.log(
+ `[transcribe] Audio enhanced, saving to S3 (${enhancedBuffer.length} bytes)`,
+ );
const [bucket] = await S3Buckets.getBucketAccess(
Option.fromNullable(bucketId),