ariym / whisper-node

Node.js bindings for OpenAI's Whisper. (C++ CPU version by ggerganov)
https://npmjs.com/whisper-node
MIT License
239 stars 41 forks source link

Importing whisper-node package changes process.cwd() #51

Open PeterCarragher opened 4 months ago

PeterCarragher commented 4 months ago

Importing whisper-node package changes process.cwd(). Verison of whisper used to repro (includes a recent patch): "@distube/ytdl-core": "github:soya-daizu/ytdl-core#sig-patch"

const whisper = require('whisper-node');
audio_file = "example.wav"
audio_path = path.join(process.cwd(), audio_file);

leads to: [whisper-node] Transcribing: /node_modules/whisper-node/lib/whisper.cpp/

Whereas the desired behavior is for process.cwd() to be set to the . The following import ordering is a workaround:

audio_file = "example.wav"
audio_path = path.join(process.cwd(), audio_file );
const whisper = require('whisper-node');

which leads to: [whisper-node] Transcribing: /

ashryanbeats commented 3 weeks ago

Same issue here.

If you're using ESM imports, the workaround above won't work for you since all the imports are pulled in before the script runs.

Instead, I'm defaulting to requiring an absolute path for my script.

Instead:

node transcribe.js ./test.wav

My script is requiring:

node transcribe.js ~/path/to/test.wav

This won't work for all use cases, but for the automation I'm building it's fine.