VACOTechSprint / ambient-transcription

Docs and management tasks for sprint
1 stars 0 forks source link

Return data to client #10

Open dahifi opened 8 months ago

dahifi commented 8 months ago

For returning the processed data to a React frontend application, especially when dealing with asynchronous operations like audio processing and ASR transcription, you can consider the following approach:

Overview

  1. Frontend Upload: The React application uploads the audio file to Google Cloud Storage using signed URLs, ensuring secure and temporary access for the upload operation.

  2. Backend Processing: After the audio file is processed through your pipeline (ASR, parsing, transcription, CSV generation, and summarization), the resulting data needs to be made accessible to the React application.

  3. Data Retrieval: The frontend periodically polls or listens for a notification indicating the completion of the processing, and then fetches the results.

Detailed Approach

Step 1: Frontend Upload

Step 2: Backend Processing

Step 3: Data Retrieval Options

You have multiple options for notifying the frontend and allowing the user to retrieve the processed data:

  1. Polling:

    • The frontend periodically sends requests to a backend service to check the status of the processing.
    • Once the processing is complete, the backend service provides URLs to access the processed data, which can be secured with signed URLs for temporary access.
  2. Push Notifications with Cloud Pub/Sub and Firebase Cloud Messaging (FCM):

    • Utilize Cloud Pub/Sub to publish processing completion messages.
    • A backend service subscribes to the Pub/Sub topic and uses Firebase Cloud Messaging to push notifications to the React application.
    • Upon receiving a notification, the frontend fetches the processed data from the provided URLs.
  3. WebSocket Connection:

    • Establish a WebSocket connection between the frontend and a backend service.
    • The backend service sends real-time updates to the frontend about the processing status and results.
    • This approach provides a more interactive experience but requires maintaining a persistent connection.
  4. Using Firestore as a Real-time Database:

    • Store the processing status and results URLs in a Firestore document.
    • The React application listens to changes on this document using Firestore's real-time capabilities.
    • When the document updates upon processing completion, the frontend automatically receives the new data and fetches the results.

Security Considerations

Example: Using Polling and Signed URLs

Backend Service (Cloud Function or App Engine)

Frontend Polling Logic

const checkProcessingStatus = async () => {
  const response = await fetch('/api/check-status');
  const data = await response.json();

  if (data.status === 'completed') {
    // Processing is complete, access the data using the provided signed URLs
    const transcriptionUrl = data.urls.transcription;
    const csvUrl = data.urls.csv;
    // Fetch the transcription and CSV using the signed URLs
    // Update the UI accordingly
  } else {
    // Continue polling if processing is not yet complete
    setTimeout(checkProcessingStatus, 5000); // Poll every 5 seconds
  }
};

// Start polling
checkProcessingStatus();

This approach, while simple, allows the React application to securely upload audio files and retrieve processed data asynchronously, providing a seamless user experience.

dahifi commented 8 months ago

Code currently returns the json object to console and appends the text response in the app.