Skip to content

Commit d12aae8

Browse files
base64 example
1 parent be1d079 commit d12aae8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/components/models/code/AutomaticSpeechRecognitionCode.astro

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,39 @@ export default {
3737
} satisfies ExportedHandler<Env>;
3838
`;
3939
40+
const workers = `import { Buffer } from 'node:buffer';
41+
42+
export interface Env {
43+
AI: Ai;
44+
}
45+
46+
const URL = "https://pub-dbcf9f0bd3af47ca9d40971179ee62de.r2.dev/02f6edc0-1f7b-4272-bd17-f05335104725/audio.mp3";
47+
48+
export default {
49+
async fetch(request, env, ctx): Promise<Response> {
50+
51+
const mp3 = await fetch(URL);
52+
if (!mp3.ok) {
53+
throw new Error(`Response status: ${mp3.status}`);
54+
}
55+
const mp3Buffer = await mp3.arrayBuffer();
56+
const base64 = Buffer.from(mp3Buffer, 'binary').toString("base64");
57+
58+
try {
59+
const res = await env.AI.run("@cf/openai/whisper-large-v3-turbo", {
60+
"audio": base64
61+
});
62+
63+
return Response.json(res);
64+
}
65+
catch (e) {
66+
console.log(JSON.stringify(env.AI));
67+
}
68+
return new Response(JSON.stringify({ho:"to"}));
69+
},
70+
} satisfies ExportedHandler<Env>
71+
`;
72+
4073
const curl = `
4174
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/${name} \\
4275
-X POST \\

0 commit comments

Comments
 (0)