Degi
Degi4w ago

Storing generated audio file doesn't work in action. Same code works fine in HTTP action.

Getting: "store() expects a Blob. If you are trying to store a Request, await request.blob() will give you the correct input." error but I am sure that I pass blob.
try {
const ttsResponse = await openaiTTS(botText);
console.log('ttsResponse', ttsResponse.status, ttsResponse.statusText);
const blobFile = await ttsResponse.blob();
console.log('blob in chat>', blobFile.type, blobFile.size, typeof blobFile);
const id = await ctx.storage.store(blobFile);
await ctx.runMutation(internal.messages.update, {
messageId: botMessageId,
patch: { audioFileId: id },
});
} catch (e) {
console.error('Error storing audio file', e, (e as Error).message);
}
try {
const ttsResponse = await openaiTTS(botText);
console.log('ttsResponse', ttsResponse.status, ttsResponse.statusText);
const blobFile = await ttsResponse.blob();
console.log('blob in chat>', blobFile.type, blobFile.size, typeof blobFile);
const id = await ctx.storage.store(blobFile);
await ctx.runMutation(internal.messages.update, {
messageId: botMessageId,
patch: { audioFileId: id },
});
} catch (e) {
console.error('Error storing audio file', e, (e as Error).message);
}
Logs verifies blobFile is actually blob too 'blob in chat>' 'audio/mpeg' 168480 'object'
4 Replies
Convex Bot
Convex Bot4w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
lee
lee4w ago
the code you provided looks fine to me. to investigate: - does the action file have "use node" at the top? - how is openaiTTS defined? my guess would be that the openai library is using a library like node-fetch instead of the built-in fetch. there's usually a way to override this in the library configuration, e.g. https://github.com/openai/openai-node?tab=readme-ov-file#customizing-the-fetch-client
GitHub
GitHub - openai/openai-node: Official JavaScript / TypeScript libra...
Official JavaScript / TypeScript library for the OpenAI API - openai/openai-node
Degi
DegiOP4w ago
Thank you for your investigation. - yes it has 'use node'; on top - import { generateBotResponse, openaiTTS } from './chat_shared'; chat_shared.ts:
import OpenAI, { toFile } from 'openai';
....
export async function openaiTTS(text: string): Promise<Response> {
const mp3 = await openai.audio.speech.create({
model: 'tts-1',
voice: 'alloy',
input: text,
});

return mp3;
}
import OpenAI, { toFile } from 'openai';
....
export async function openaiTTS(text: string): Promise<Response> {
const mp3 = await openai.audio.speech.create({
model: 'tts-1',
voice: 'alloy',
input: text,
});

return mp3;
}
import 'openai/shims/web'; adding this to chat_shared.ts fixed. Thank you so much 🙏
lee
lee4w ago
great! you could also try removing the "use node";

Did you find this page helpful?