I am trying to build an application in Node Js, in which the user enters the Youtube Url, and then there's a function at the backend which is extracting the audio from the url using a library called, ytdl-core.
After the audio has been extracted, rather than saving it temporarily I want it to directly pass it to the whisper API.
export const extractAudio = internalAction({
args: { url: v.string() },
handler: async (ctx, args) => {
try {
const videoId = ytdl.getURLVideoID(args.url);
const isValidId = ytdl.validateID(videoId);
if (!isValidId) {
throw new Error("Invalid video Id.");
}
const info = await ytdl.getInfo(videoId);
const audioFormats = ytdl.filterFormats(info.formats, "audioonly");
const audioUrl = audioFormats?.[0]?.url;
if (!audioUrl) {
throw new Error("Unable to extract audio from video.");
}
console.log(audioUrl);
} catch (error) {
console.log(error);
return error;
}
},
});
This is what I have yet, I have the url which plays the audio in chrome.