100% FREE & LOCAL Transcription

Follow best practices and develop responsibly. This code is not perfect and has flaws. You are responsible for the code you run.

Prerequisites

Node JS

You will need this to run the server.

# Verify installation
node -v
npm -v 
 

FFMPEG

The whisper module seems to need this to convert the audio into a suitable format.

Depending on your OS this will vary. You can google it for your system or you can check out the link:


If you’re comfortable with running python and executing code from the terminal, you can skip the rest of this blog and simply check out this package:

Whisper GitHub Setup


Initialize the project

First create an empty folder and inside a terminal navigate to that folder. Run the following code:

npm init

This will initialize the folder to hold a node project. Install the following modules:

npm install express body-parser nodejs-whisper
npx nodejs-whisper download

The above code will first install all the packages needed for the upcoming script. It will also download the model needed for the transcription.

If asked about which model to download, simply select the base.en model

Create a new file called index.js and copy into it - View Code Here

The code above will create a server on port 3000 that will listen for POST requests. If given an audio file in its payload it will first write the audio file to your disk, then use whisper to transcribe it which also create a another file with the transcribed text. Lastly it will read the file and send the text data back to the client that called.

This is NOT a secure way to handle this type of function. It is highly susceptible for various XSS attacks. I would suggest using this only on an isolated local network.

To start the server:

node index.js

You can test it be sending a webm or mp3 file using curl

curl -X POST http://localhost:3000/transcribe \
     -H "Content-Type: audio/mpeg" \
     --data-binary @audio.webm

This worked for me but I was not able to test it on other machines (mac/windows). Like any code found on the internet, it may require some tweaking to work. Feel free to paste the code into GPT to get additional help if you encounter an error.

Next
Next

How to Trigger Smart Home Automations with Notion & Webhooks