import { OpenAI } from 'https://deno.land/x/openai@v4.20.1/mod.ts' const openai = new OpenAI({ apiKey: Deno.env.get('OPENAI_API_KEY') }) export async function processAudioWithWhisper(audioUrl: string): Promise { try { // Download do áudio const audioResponse = await fetch(audioUrl) if (!audioResponse.ok) { throw new Error('Falha ao baixar áudio') } const audioBlob = await audioResponse.blob() // Debug do áudio console.log('Audio blob:', { size: audioBlob.size, type: audioBlob.type }) // Converte Blob para File const audioFile = new File([audioBlob], 'audio.mp3', { type: audioBlob.type || 'audio/mpeg' }) // Transcrição com Whisper const transcription = await openai.audio.transcriptions.create({ file: audioFile, model: 'whisper-1', language: 'pt' // removido response_format pois estava causando erro }) console.log('Transcription response:', transcription) // Debug if (!transcription || typeof transcription === 'undefined') { throw new Error('Resposta da transcrição vazia') } return transcription.text || '' } catch (error) { console.error('Erro detalhado na transcrição:', error) throw error } }