[FREE API] Convert Any File To Text (ChatGPT + more use cases)

Hello,

Another free API available, with ChatGPT building the docs that I don’t have the patience to write (I have verified information is correct):

(Pretty Much) Anything To Text

Asset 3 copy
by Not Quite Unicorns


Demo: Try it out here

Anything To Text

API Reference

Overview

This API provides a service to extract text from various file types and online sources (like YouTube). After processing the provided data, it sends the result asynchronously to a specified webhook.

Base URL

The base URL for this API is specific to where it’s deployed. If hosted on Google App Engine, it would look like:

https://YOUR_PROJECT_ID.REGION_ID.r.appspot.com

Replace YOUR_PROJECT_ID with your Google Cloud project ID and REGION_ID with the region where the app is deployed.

Endpoints

/convert

Method:

  • POST

Description:

Receives a file or URL for text extraction. Once the extraction is complete, it sends the result to the provided webhook.

Headers:

  • x-api-key: API key for authentication.
  • OpenAIAPIKey (optional): Required only if the uploaded file is an audio or video type. Used for transcribing audio data.

Parameters:

  • Form data:
    • file (optional): The file from which text needs to be extracted.
    • url (optional): URL from which text needs to be extracted. Can be a standard webpage or a YouTube video link.
    • webhookURL: The URL where the text result should be posted after processing.
    • uniqueID: A unique identifier for this request.

Responses:

  • 401 Unauthorized: Invalid or missing API key.
  • 400 Bad Request: Missing required parameters.
  • 400 Bad Request: OpenAIAPIKey is required for audio files.
  • 202 Accepted: File or URL received for processing.

Notes:

  • Only one of file or url should be provided in a single request.
  • The API processes the data asynchronously. Once the data is processed, it sends the result to the provided webhookURL.

Webhook Payload

Once processing is complete, the API sends the result to the specified webhookURL in the following format:

{
    "text": "Extracted text goes here...",
    "uniqueID": "Provided unique identifier",
    "processingTime": "Time taken in seconds",
    "filetype": "Type of the file or URL"
}

Or in case of an error:

{
    "error": "Error description goes here...",
    "uniqueID": "Provided unique identifier",
    "processingTime": "Time taken in seconds",
    "filetype": "Type of the file or URL"
}

Supported File Types:

  • Audio: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm
  • Documents: pdf, docx, xlsx, csv, txt, pptx, html, xml, json
  • Web: youtube, url

For audio transcriptions, the API uses OpenAI’s Whisper model. Ensure you provide the OpenAIAPIKey header for audio files.

Usage Examples:


Manually enter API response:

  "body": {
    "status": "Received URL. Processing..."
  },
  "error": {
    "status_code": 202,
    "status_message": "Accepted",
    "body": "\"{\\n  \\\"status\\\": \\\"Received URL. Processing...\\\"\\n}\\n\""
  },
  "returned_an_error": false,
  "headers": {
    "content-type": "application/json",
    "x-cloud-trace-context": "0fe010ee517d6f50c55cf137f7b93cc7;o=1",
    "date": "Tue, 22 Aug 2023 09:37:32 GMT",
    "server": "Google Frontend",
    "content-length": "46",
    "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
  }
}

Create a backend API workflow ‘fileconversion’ that is exposed publicly. Initialise it using the API connector request and specifying the webhook URL as the initialisation URL.

Error Handling:

  • Ensure you provide the correct API key using the x-api-key header.
  • For audio transcriptions, ensure you provide the OpenAI API key using the OpenAIAPIKey header.
  • Ensure the file or URL is of a supported type.
  • Check the response for any error messages and adjust your request accordingly.

Common issues

  • Send a file, not a file URL. Literally copy the Bubble API connector screenshot and you’ll be fine
  • Web scraping doesn’t render Javascript
  • Max 32MB per file

Download

You can self host this API. The download is here: Dropbox - Convert to text - Simplify your life

Change the API key in the main.py file before deploying.


If you’d like me to deploy this on your behalf, you can DM me or contact via https://notquiteunicorns.xyz. The costs of hosting it are rather negligible compared to websites like ConvertAPI that charge $0.01-$0.05 per conversion. After deploying the only costs are the server - you don’t need me for anything.

Somewhat unrelated, I’m doing free Bubble app audits. Visit the website if you’d like one :slight_smile:

1 Like

Updated with the following changes:

  • It will now return the converted file via webhook rather than API request response to avoid timeout (a 1000 page PDF takes about 3 minutes on GCP F2 instance)
  • Audio and video now supported with OpenAI Whisper API
  • Max 32MB per file (GCP limitation)
1 Like