Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/content/__tests__/selectAttachedAudioClip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ describe("selectAttachedAudioClip", () => {
expect(result.songTitle).toBe("my-track");
});

it("decodes URL-encoded filenames from Slack URLs", async () => {
vi.mocked(transcribeSong).mockResolvedValue({
title: "Singin in the Rain 2",
fullLyrics: "",
segments: [],
});
vi.mocked(analyzeClips).mockResolvedValue([]);

const result = await selectAttachedAudioClip({
audioUrl: "https://blob.vercel-storage.com/content-attachments/audio/1774985247995-Singin%20in%20the%20Rain%202.mp3",
lipsync: false,
});

expect(result.songFilename).toBe("1774985247995-Singin-in-the-Rain-2.mp3");
expect(result.songTitle).toBe("1774985247995-Singin-in-the-Rain-2");
});

it("transcribes the downloaded audio", async () => {
vi.mocked(transcribeSong).mockResolvedValue({
title: "song",
Expand Down
4 changes: 2 additions & 2 deletions src/content/selectAttachedAudioClip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export async function selectAttachedAudioClip({
const arrayBuffer = await response.arrayBuffer();
const songBuffer = Buffer.from(arrayBuffer);

// Derive filename from URL
// Derive filename from URL (decode %20, replace spaces for fal.ai compat)
const urlPath = new URL(audioUrl).pathname;
const songFilename = urlPath.split("/").pop() ?? "attached-audio.mp3";
const songFilename = decodeURIComponent(urlPath.split("/").pop() ?? "attached-audio.mp3").replace(/\s+/g, "-");
const songTitle = songFilename.replace(/\.(mp3|wav|m4a|ogg|aac)$/i, "");

logStep("Attached audio downloaded", { songTitle, sizeBytes: songBuffer.byteLength });
Expand Down
52 changes: 41 additions & 11 deletions src/content/transcribeSong.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,52 @@ export async function transcribeSong(
songBuffer: Buffer,
songFilename: string,
): Promise<SongLyrics> {
logger.log("Transcribing song", { filename: songFilename });
logger.log("Transcribing song", {
filename: songFilename,
bufferSize: songBuffer.byteLength,
});

// Upload audio to fal storage
const file = new File([songBuffer], songFilename, { type: "audio/mpeg" });
const audioUrl = await fal.storage.upload(file);
logger.log("Uploading audio to fal storage", {
fileName: file.name,
fileSize: file.size,
fileType: file.type,
});

let audioUrl: string;
try {
audioUrl = await fal.storage.upload(file);
logger.log("Audio uploaded to fal storage", { audioUrl });
} catch (uploadError) {
logger.log("fal.storage.upload failed", {
error: String(uploadError),
message: (uploadError as Error).message,
});
throw uploadError;
}

// Transcribe with Whisper
const result = await fal.subscribe("fal-ai/whisper" as string, {
input: {
audio_url: audioUrl,
task: "transcribe",
chunk_level: "word",
language: "en",
},
logs: true,
});
let result;
try {
result = await fal.subscribe("fal-ai/whisper" as string, {
input: {
audio_url: audioUrl,
task: "transcribe",
chunk_level: "word",
language: "en",
},
logs: true,
});
} catch (whisperError) {
logger.log("fal-ai/whisper failed", {
error: String(whisperError),
message: (whisperError as Error).message,
audioUrl,
filename: songFilename,
});
throw whisperError;
}

const data = result.data as unknown as {
text?: string;
Expand Down
Loading