serenadeai / speech-recorder

speech-recorder is a node.js module for streaming audio from a device's microphone and filtering for speech.
MIT License
86 stars 19 forks source link

ibc++abi: terminating with uncaught exception of type Napi::Error: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Int16Array #25

Closed richastral closed 1 year ago

richastral commented 2 years ago

Running the simple example:

const { SpeechRecorder } = require("speech-recorder"); const fs = require('fs');

const writeStream = fs.createWriteStream("audio.raw"); const recorder = new SpeechRecorder({ onAudio: ({ audio }) => { writeStream.write(audio); } });

console.log("Recording for 5 seconds..."); recorder.start(); setTimeout(() => { console.log("Done!"); recorder.stop(); }, 5000);

and I get the error:

ibc++abi: terminating with uncaught exception of type Napi::Error: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Int16Array

No matter what I do I get this error, what am I doing wrong?

tmacwill commented 2 years ago

hi there! mind providing some more information about your system? OS, version, node version, etc?

joaomrsouza commented 1 year ago

i'm with the same problem, except that i don't get this error message, i't just crash. My code is pretty much the same, is from the example on the readme

VityaSchel commented 4 weeks ago

anyone succeeded?

y-lobau commented 5 days ago

I think the reason is that the stream in fact expects the 'string or an instance of Buffer or Uint8Array', and the library provides something different like raw bytes. Try wrapping like this:

Buffer.from(audio.buffer, audio.byteOffset, audio.byteLength)