Ich arbeite an einem Projekt, bei dem ich mit dem Flüstermodell von OpenAI in einem Google Cloud -Speicher -Bucket Audio transkribieren muss. Das Audio wird im Webm-Format mit OPUS-Codierung gespeichert. Aufgrund der Dateigröße stream ich das Audio in 30-Sekunden-Stücken. Der erste Chunk konvertiert erfolgreich, aber nachfolgende Stücke konvertieren nicht. Ich vermute, dies liegt daran, dass jedem Chunk den Header des Webm -Containers fehlt, den FFMPEG den Opus -Codec richtig interpretieren muss. von Webm/opus bis wav.
Ich arbeite an einem Projekt, bei dem ich mit dem Flüstermodell von OpenAI in einem Google Cloud -Speicher -Bucket Audio transkribieren muss. Das Audio wird im Webm-Format mit OPUS-Codierung gespeichert. Aufgrund der Dateigröße stream ich das Audio in 30-Sekunden-Stücken. Der erste Chunk konvertiert erfolgreich, aber nachfolgende Stücke [url=viewtopic.php?t=12659]konvertieren[/url] nicht. Ich vermute, dies liegt daran, dass jedem Chunk den Header des Webm -Containers fehlt, den FFMPEG den Opus -Codec richtig interpretieren muss. von Webm/opus bis wav. [code]async def handle_transcription_and_notify( consultation_service: ConsultationService, consultation_processor: ConsultationProcessor, consultation: Consultation, language: str, notes: str, clinic_id: str, vet_email: str, trace_id: str, blob_path: str, max_retries: int = 3, retry_delay: int = 5, max_concurrent_tasks: int = 3 ): """ Handles the transcription process by streaming the file from GCS, converting to a compatible format, and notifying the client via WebSocket. """ chunk_duration_sec = 30 # 30 seconds per chunk logger.info(f"Starting transcription process for consultation {consultation.consultation_id}", extra={'trace_id': trace_id})
# Initialize GCS client service_account_key = os.environ.get('SERVICE_ACCOUNT_KEY_BACKEND') if not service_account_key: logger.error("Service account key not found in environment variables", extra={'trace_id': trace_id}) await send_discord_alert( f"Service account key not found for consultation {consultation.consultation_id}.\nTrace ID: {trace_id}" ) return
try: service_account_info = json.loads(service_account_key) credentials = service_account.Credentials.from_service_account_info(service_account_info) except Exception as e: logger.error(f"Error loading service account credentials: {str(e)}", extra={'trace_id': trace_id}) await send_discord_alert( f"Error loading service account credentials for consultation {consultation.consultation_id}.\nError: {str(e)}\nTrace ID: {trace_id}" ) return
# Initialize GCS client service_account_key = os.environ.get('SERVICE_ACCOUNT_KEY_BACKEND') if not service_account_key: logger.error("Service account key not found in environment variables", extra={'trace_id': trace_id}) await send_discord_alert( f"Service account key not found for consultation {consultation.consultation_id}.\nTrace ID: {trace_id}" ) return
try: service_account_info = json.loads(service_account_key) credentials = service_account.Credentials.from_service_account_info(service_account_info) except Exception as e: logger.error(f"Error loading service account credentials: {str(e)}", extra={'trace_id': trace_id}) await send_discord_alert( f"Error loading service account credentials for consultation {consultation.consultation_id}.\nError: {str(e)}\nTrace ID: {trace_id}" ) return
async def stream_blob_in_chunks(blob, chunk_size): loop = asyncio.get_running_loop() start = 0 size = blob.size while start < size: end = min(start + chunk_size - 1, size - 1) try: logger.info(f"Requesting chunk from {start} to {end}", extra={'trace_id': trace_id}) chunk = await loop.run_in_executor( None, lambda: blob.download_as_bytes(start=start, end=end) ) if not chunk: break logger.info(f"Yielding chunk from {start} to {end}, size: {len(chunk)} bytes", extra={'trace_id': trace_id}) yield chunk start += chunk_size except Exception as e: logger.error(f"Error downloading chunk from {start} to {end}: {str(e)}", exc_info=True, extra={'trace_id': trace_id}) raise e
async def convert_to_wav(chunk_bytes, chunk_idx): """ Convert audio chunk to WAV format compatible with Whisper, ensuring it's 16 kHz, mono, and 16-bit PCM. """ try: logger.debug(f"Processing chunk {chunk_idx}: size = {len(chunk_bytes)} bytes")
detected_format = await detect_audio_format(chunk_bytes) logger.info(f"Detected audio format for chunk {chunk_idx}: {detected_format}") input_io = io.BytesIO(chunk_bytes) output_io = io.BytesIO()
# ffmpeg command to convert webm/opus to WAV with 16 kHz, mono, and 16-bit PCM
# ffmpeg command with debug information ffmpeg_command = [ "ffmpeg", "-loglevel", "debug", "-f", "s16le", # Treat input as raw PCM data "-ar", "48000", # Set input sample rate "-ac", "1", # Set input to mono "-i", "pipe:0", "-ar", "16000", # Set output sample rate to 16 kHz "-ac", "1", # Ensure mono output "-sample_fmt", "s16", # Set output format to 16-bit PCM "-f", "wav", # Output as WAV format "pipe:1" ]
process = subprocess.Popen( ffmpeg_command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE )
# Convert to WAV format wav_io = await convert_to_wav(chunk_bytes, idx) if not wav_io: logger.error(f"Failed to convert chunk {idx + 1} to WAV format.") return ""
Ich habe einen Datenfluss in einer Fastapi -Anwendung, bei der ein potenziell sehr großer HTTP -Put -Körper hochgeladen wird, und ich muss dies auf Google Cloud -Speicher streamen. Ich verwende die...
Ich baue ein QA-System auf rappenbasiertem Dokument mit Python (no Langchain), Lama (50K-Kontext), PostgreSQL mit PGVector und Docling for Parsing. Benutzer können bis zu 10 große Dokumente hochladen...