-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx.tool.mjs
26 lines (22 loc) · 852 Bytes
/
tx.tool.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { File } from 'buffer';
export default async function transcribeAudio({ file }, ctx) {
const url = "https://api.groq.com/openai/v1/audio/transcriptions";
const formData = new FormData();
const filename = ctx.resolve(file);
let buf = ctx.read(filename);
buf = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)
formData.append('file', new File([buf], file));
formData.append('model', 'whisper-large-v3');
formData.append('response_format', 'text');
const response = await fetch(url, {
method: 'POST',
headers: {
"Authorization": `Bearer ${ctx.env.GROQ_KEY}`
},
body: formData,
});
if (!response.ok) {
throw new Error(`Error: ${response.status} ${response.statusText} ${await response.text()}`);
}
return await response.text();
}