Skip to content

POST process_audio_v2

Do Le Long An edited this page Aug 23, 2024 · 6 revisions

API Documentation: process_audio_v2 Endpoint

Endpoint Overview

  • Endpoint: POST /process_audio_v2/{user_id}
  • Tag: process-audio
  • Description: This endpoint is used to initiate the processing of an audio file. The processing is handled in the background via a Celery task. The client can pass various parameters related to the audio file, such as file_id, file_extension, and file_name. The response includes a message confirming that the task has been dispatched and provides a task_id for tracking the background process.

URL

POST /process_audio_v2/{user_id}

Path Parameters

  • user_id (required): The unique identifier for the user who owns the audio file.

Query Parameters

  • file_id (optional): A unique identifier for the audio file.
  • file_extension (optional): The extension of the audio file (e.g., m4a, mp3). The default is m4a.
  • file_name (optional): The name of the audio file.

Example Request

Example of URL with user_id and file_id Query Parameters:

POST https://medvoice-fastapi.ngrok.dev/process_audio_v2/12345?file_id=67890
  • user_id: 12345
  • file_id: 67890

Example Request in Dart:

import 'package:http/http.dart' as http;

Future<void> processAudio(String userId, String? fileId, String? fileExtension, String? fileName) async {
  final String baseUrl = "https://medvoice-fastapi.ngrok.dev";
  final Uri url = Uri.parse('$baseUrl/process_audio_v2/$userId')
      .replace(queryParameters: {
        if (fileId != null) 'file_id': fileId,
      });

  final response = await http.post(url);

  if (response.statusCode == 200) {
    final responseBody = response.body;
    print('Response: $responseBody');
    // Parse the response and handle the data (e.g., task_id) as needed
  } else {
    print('Failed to start audio processing: ${response.statusCode}');
  }
}

Response

  • Status Code: 200 OK
  • Content-Type: application/json
Response Body
{
  "message": "Audio processing started in the background",
  "task_id": "string"  // A unique identifier for the background task
}

Error Handling

  • Status Code: 500 Internal Server Error
    • This status is returned if there is an error while dispatching the task. The error details will be included in the response body.

Response Example

A successful response might look like this:

{
  "message": "Audio processing started in the background",
  "task_id": "d91a4f0e-09f1-4c6f-bbde-8fcb7b0a8b7b"
}

Notes for Mobile Team

  • Ensure that the user_id is correctly passed in the URL path.
  • Optional parameters like file_id, file_extension, and file_name should be added as query parameters only if they are available.
  • The task_id returned in the response can be used to track the status of the audio processing task, depending on your application's needs.
  • This API uses background processing, so the audio processing will happen asynchronously. The client does not need to wait for the processing to complete before receiving a response.

References

  • For more details on how to handle HTTP requests in Flutter/Dart, you can refer to the official Flutter documentation.