ChetanXpro / nodejs-whisper

NodeJS Bindings for Whisper - the CPU version of OpenAI's Whisper, as initially crafted in C++ by ggerganov.
https://npmjs.com/nodejs-whisper
MIT License
89 stars 22 forks source link

Issue with spaces in path for .wav #125

Open HeyEvgenii opened 1 week ago

HeyEvgenii commented 1 week ago

Facing issues then the filepath to the .wav file contains spaces '/Users/me/Desktop/some folder with space in name/ audioFile.wav' - won't work, moving file somewhere with no spaces in path, works fine

macos 14.1, M3 max, however running vscode on intel version

alexIV-0 commented 1 week ago

Yeah, I ran into that too. In the end I just wrote a function that moves the wav file to the TEMP folder, since there are no spaces there, and renames the file to something without spaces.
Then I pass it through whisper and then transfer the resulting files back to the folder where the wav file came from.

Yes, it was a bit complicated, but now it works everywhere.

    const tempFolderForWhisper = testAndCreateFolder(path.join(tempPath, 'whisper'));
    const tempName = 'createTitle.wav';
    const newPath = path.join(tempFolderForWhisper, tempName);
    await copyFile(filePath.path, newPath, false);
    const transcript = await nodewhisper(newPath, options);
    const fileInFolder = getSomeFromFolder(tempFolderForWhisper, ['text', 'title']);
    if (fileInFolder.length > 0) {
        for (let curFile of fileInFolder) {
            const pathFrom = path.join(tempFolderForWhisper, curFile);
            const pathTo = path.join(
                path.dirname(filePath.path),
                `${path.basename(filePath.path, path.extname(filePath.path))}${path.extname(curFile)}`
            );
            const res = await moveFile(pathFrom, pathTo);
            if (res != '') {
                finalFile.push(res);
            }
        }
    }

    fs.rmdirSync(tempFolderForWhisper, { recursive: true });