Coder Social home page Coder Social logo

Comments (5)

ahmetoner avatar ahmetoner commented on May 26, 2024 1

Have you tried using Postman code snippets for making Node.js requests?

from whisper-asr-webservice.

ayancey avatar ayancey commented on May 26, 2024

Post code pls

from whisper-asr-webservice.

asktimfisher avatar asktimfisher commented on May 26, 2024

I'm using NodeJS and the form-data package to send a WAV buffer to the ASR endpoint. I know the audio coming into the function is good because I can use it via Postman with the Whisper endpoint and it works great.

async function transcribeAudio(socket, audioBuffer) {
const formData = new FormData();
formData.append("audio_file", audioBuffer, {
contentType: "audio/wav",
filename: "audio.wav",
});

const whisperUrl =
"http://192.168.0.10:9000/asr?task=transcribe&language=en&encode=true&output=json&word_timestamps=false";

try {
const response = await fetch(whisperUrl, {
method: "POST",
body: formData,
headers: formData.getHeaders(),
});

if (!response.ok) {
  socket.emit(
    "clientConsole",
    `Whisper HTTP error! Status: ${response.status}`
  );
}

const data = await response.json();
const transcription = data.text;

console.log("Transcribed text:", transcription);
socket.emit("clientConsole", `Transcribed text: ${transcription}`);

} catch (error) {
console.error("Error during Whisper transcription: ", error);
return null;
}
}
`

But I get "undefined" returned and a "Did not find boundary character 91 at index 2" in the logs.

This is the first time I'm POSTing with form data in Node so I certainly could be crafting something wrong.

(sorry for the bad formatting - on my phone)

from whisper-asr-webservice.

asktimfisher avatar asktimfisher commented on May 26, 2024

No!! I didn't know that was an option! That's a great idea. I'll try that when I get home. At very least, even if that fails, it should make it clear if perhaps I'm missing a step (since I'm using a legit file in Postman vs a buffer (same audio data) in the code). Thanks for the idea!

from whisper-asr-webservice.

asktimfisher avatar asktimfisher commented on May 26, 2024

Thanks so much for the recommendation! I was able to create the following NodeJS code that accepts a WAV buffer. Works perfectly. I think switching to axios from the native fetch did the trick:

async function transcribeAudio(buffer) {
  let data = new FormData();
  data.append('audio_file', buffer, 'file.wav');

  let config = {
    method: 'post',
    maxBodyLength: Infinity,
    url: 'http://192.168.0.10:9000/asr?task=transcribe&language=en&encode=true&output=json&word_timestamps=false',
    headers: {
      ...data.getHeaders(),
    },
    data: data,
  };

  try {
    const response = await axios.request(config);
    console.log(JSON.stringify(response.data));
  } catch (error) {
    console.log(error);
  }
}

from whisper-asr-webservice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.