This project is an API that utilizes OpenAI's Whisper API to convert audio files to text. The code is built with Node.js and utilizes frameworks like Express.js and Multer to handle HTTP requests and file uploading.
- The client sends a request with an audio file to the server.
The server extracts the audio file and creates a
FormData
object. TheFormData
object is configured with the OpenAI Whisper model and the selected audio file. - A
POST
request is sent to the OpenAI API to convert the audio file to text. - The server extracts the resulting text from the OpenAI API response.
- The text is sent back to the client in the response body.
- The uploaded audio file is deleted from the server.
- Node.js v14 or later
- OpenAI API Key
- Clone the repository to your local machine.
git clone https://github.com/KuNDevQ/OpenAI-Whisper-API.git
- Navigate to the project directory in your terminal.
cd OpenAI-Whisper-API
- Install the project dependencies.
npm install
- Set the value for the OPENAI_API_KEY environment variable:
- For Windows: set OPENAI_API_KEY=your_api_key_here
- For macOS or Linux: export OPENAI_API_KEY=your_api_key_here
- Start the server.
npm start
- Use a tool like Postman to send a
POST
request tohttp://localhost:5000/whisper
, with amultipart/form-data
body containing an audio file.
- Change the port number by setting the value of the
PORT
environment variable. - Change the OpenAI model by modifying the
model
value in theFormData
object. - Change the audio file size limit by modifying the
limits
object in theMulter
configuration.
Abdulmalik Al-Qahtani (@kundevq)