Node.js file path issue on Windows
Transferring a patch written on Mac to Windows running vosk and sox. Installed the necessary libraries and of course node.js on the PC, and only changed the file paths in the code without touching anything else.
This is the code with the file paths:
var vosk = require('C:\Users\lab\Documents\Max 8\Projects\tansy-control\code\node_stuff\node_modules\vosk'); /// !!! This is where I put the folder.
var sox = require('sox');
const { Readable } = require("stream");
const wav = require("wav");
const fs = require("fs");
const Max = require('max-api');
const { delimiter } = require("path");
const paths = process.env.PATH.split(delimiter);
paths.push("C:\Program Files (x86)\sox-14-4-2"); /// !!! This is where I installed sox (sox.exe)
process.env.PATH = paths.join(delimiter);
var mic = require("mic");
MODEL_PATH = "C:\Users\lab\Documents\Vosk\vosk-model-en-us-0.22" /// !!! language model path
SAMPLE_RATE = 16000
if (!fs.existsSync(MODEL_PATH)) {
console.log("Please download the model from https://alphacephei.com/vosk/models and unpack as " + MODEL_PATH + " in the current folder.")
process.exit()
}
vosk.setLogLevel(0);
const model = new vosk.Model(MODEL_PATH);
const rec = new vosk.Recognizer({model: model, sampleRate: SAMPLE_RATE});
var micInstance = mic({
rate: String(SAMPLE_RATE),
channels: '1',
debug: false
});
var micInputStream = micInstance.getAudioStream();
micInstance.start();
micInputStream.on('data', data => {
if (rec.acceptWaveform(data))
Max.outlet(rec.result()); //whole text after pause
else
Max.outlet(rec.partialResult()); //word by word, but accumulates
});
process.on('SIGINT', function() {
Max.post(rec.finalResult());
Max.post("\nDone");
rec.free();
model.free();
});
and I received this error message, it can't even find the module in line 1:

Since node.js has great cross-platform support, it's likely the file paths that went wrong.
I tried path.normalize() and it didn't help. Any suggestions on how to write the file paths on Windows?