Basic Node Whisper starter

Here’s a very basic example of serving the one click whisper model to get started. You’ll have to handle receiving the audio as this just uses a local audio file.

const express = require("express");
const banana = require("@banana-dev/banana-dev");
const fs = require("fs");
const app = express();
const port = 3002;

const apiKey = ""; // "YOUR_API_KEY"
const whKey = ""; // "YOUR_WH_KEY"

// read an mp3 into bytes and then into a base64 string
var audio = fs.readFileSync("./jfk.opus");
var audioBase64 = Buffer.from(audio).toString("base64");
const inputs = {
  // a json specific to your model. For example:
  mp3BytesString: audioBase64,
};

// get request at /whisper that calls banana api and returns output to client
app.get("/whisper", async function (req, res) {
  console.log(req.body);
  try {
    let modelOutputs = await banana.run(apiKey, whKey, inputs);
    console.log(modelOutputs.modelOutputs);
    res.send(modelOutputs);
  } catch (error) {
    console.error(error);
    let result = "error";
    res.send(result);
  }
});

app.listen(port, () => {
    console.log(`Listening on port ${port}`)
  })
1 Like

Legend! Thanks for posting. This Whisper forum was feeling very lonely :sweat_smile:

1 Like