export async function extractAudioFromVideo(
videoBuffer: ArrayBuffer,
outputFileName: string = 'test-sample',
options: ExtractAudioOptions = {}
): Promise<ArrayBuffer> {
const apiUrl = 'https://api.apyhub.com/extract/video/audio/file';
const token = process.env.CONVEX_APY_TOKEN;
if (!token) {
throw new Error('CONVEX_APY_TOKEN environment variable is not set');
}
const params = new URLSearchParams();
params.append('output', outputFileName);
if (options.startTime) params.append('start_time', options.startTime);
if (options.duration) params.append('duration', options.duration);
if (options.outputFormat) params.append('output_format', options.outputFormat);
const response = await fetch(`${apiUrl}?${params.toString()}`, {
method: 'POST',
headers: {
'apy-token': token,
'Content-Type': 'application/octet-stream',
},
body: videoBuffer
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.arrayBuffer();
}