如何使用npm mp3进行wav [英] How to use npm mp3 to wav
问题描述
当尝试使用 npm mp3-to-wav
将 mp3 转换为 wav 时,控制台会返回
When attempting to convert an mp3 to wav using npm mp3-to-wav
, the console returns,
"mp3到wav exec错误:saveForWav错误:路径必须是字符串.['C:\ Projects \ Weatherman \ meme.wav']"
"mp3 to wav exec err: saveForWav err: Path must be a string. Received [ 'C:\Projects\Weatherman\meme.wav' ]"
我相当确定我要喂的东西是字符串,所以我不知道问题出在哪里.可以在npm mp3-to-wav > https://www.npmjs.com/package/mp3-to-wav#2-usage ,这是我的代码.
I'm fairly certain what I'm feeding it is a string, so I have not a clue where the problem lies. npm mp3-to-wav
can be found at https://www.npmjs.com/package/mp3-to-wav#2-usage and here's my code.
const Mp32Wav = require('mp3-to-wav');
new Mp32Wav("C:/Projects/Weatherman/meme.MP3").exec()
如何获取文件以接收目录路径,我的目录路径是否有问题?
How do I get the file to receive the directory path and is there a problem with my directory path?
推荐答案
您得到的错误不是来自"mp3-to-wav",而是来自fs
路径没有任何问题
the err you get is not from 'mp3-to-wav' its from fs
there isnt any problem with your path
class Mp32Wav {
constructor(input_file_path, output_dir) {
if (!utils.checkArgsNotNull(...input_file_path)) {
throw new Error('err arguments')
}
output_dir = utils.judgeNotNull(output_dir) ? output_dir : utils.splitFileDir(input_file_path)
this._input_file_path = input_file_path
this._input_file_name = utils.splitFilename(input_file_path)
this._output_dir = output_dir
this._output_file_name = this._input_file_name.toString().replace(/\.mp3/i, '')
}
正如您在其构造函数中看到的那样,他们忽略了区分大小写的
as you can see in their constructor they ignore case sensitive
.replace(/\.mp3/i, '')
我不使用Windows,但我认为使用path模块创建路径并检查其绝对路径将对您有所帮助
I don't use windows but I think it will be helpful for you to use path module to create your path and check if its absolute
Node.js path.isAbsolute()方法
https://www.w3schools.com/nodejs/met_path_isabsolute.asp
而且,w3c中的所有示例都在Windows中使用双\\插入\\
例如
console.log(path.isAbsolute('C:\\test\\demo_path.js')); //true
这篇关于如何使用npm mp3进行wav的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!