How to change mp3 file to wav file in node.js - fluent-ffmpeg

I am trying to convert mp3 file to wav file but I am not getting idea how to do that, I tried using fluent-ffmpeg library but I don't know how to use that.

I finally figured it out using 'fluent-ffmpeg' library. Here is my code.
const ffmpeg = require('fluent-ffmpeg');
let track = './source.mp3';//your path to source file
ffmpeg(track)
.toFormat('wav')
.on('error', (err) => {
console.log('An error occurred: ' + err.message);
})
.on('progress', (progress) => {
// console.log(JSON.stringify(progress));
console.log('Processing: ' + progress.targetSize + ' KB converted');
})
.on('end', () => {
console.log('Processing finished !');
})
.save('./hello.wav');//path where you want to save your file
if you are facing
An error occurred: Cannot find ffmpeg
then add the ffmpeg path in system environment variables. Your VSCode still may dont recognise the ffmpeg command so in that case re-start VSCode.

Related

Loading Vue devtools in electron in development mode

I was looking for a way to add Vue Devtools to the electron app I was working on. I tried a couple of methods that seemed to be outdated and finally succeded using this package:
electron-devtools-installer which I installed as a DEV dependency.
with this code:
import { app } from 'electron'
import installExtension from 'electron-devtools-installer';
const VUEJS3_DEVTOOLS = 'nhdogjmejiglipccpnnnanhbledajbpd';
...
app.whenReady().then(() => {
installExtension(VUEJS3_DEVTOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
});
but since this was a DEV dependency, the app fails to load due to the missing package in production.
I was wondering if there is a way to dynamicly load the package/extension only if not in production.
It took me many attempts to figure this out since this isn't directly documented anywhere and I lack the experience of loading ES6 modules to think of trying module.default.default.
This is the code that ended up working without issues in both development and production cases:
app.whenReady().then(() => {
if (process.env.DEBUGGING) // replace with whatever you use to check for dev env
import('electron-devtools-installer')
.then(mymodule => {
const installExtension = mymodule.default.default; // Default export
installExtension(mymodule.default.VUEJS_DEVTOOLS) // replace param with the ext ID of your choice
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
}).catch((err) => console.log('An error occurred: ', err));
}).catch((err) => console.log('An error occurred: ', err));
There might be a more elegant way to do this but this is all I needed. I am open to hear improvements on this.
Note: replace mymodule.default.VUEJS_DEVTOOLS with any other valid Chrome extension ID. The package has some popular ones built-in: Electron DevTools Installer - GitHub

Error when moving file with react-native-fs, file already exist

I am trying to move an image to the library using react-native-fs in iOS
const originalPath = "/private/var/mobile/Containers/Data/Application/7EB7B0CB-FCA8-49EE-843A-04BBB0B286B1/tmp/ReactNative/E70143FD-21A8-42AA-BFD2-A8FA45D7D93A.png"
const destinationPath = RNFS.LibraryDirectoryPath + "/kj3.jpg";
RNFS.moveFile(screenShotPath, destinationPath).then((data) => {
console.log(data)
}).catch((err) => {
throw err
})
The destination path in this case is
/var/mobile/Containers/Data/Application/7EB7B0CB-FCA8-49EE-843A-04BBB0B286B1/Library/kj3.jpg
I get an error
Error: “E70143FD-21A8-42AA-BFD2-A8FA45D7D93A.png” couldn’t be moved to “Library” because an item with the same name already exists.
I also get the same error when I try to copy the file.

Process download file before save

import RNBackgroundDownloader from 'react-native-background-downloader';
let task = RNBackgroundDownloader.download({
id: 'file123',
url: 'https://link-to-very.large/file.zip'
destination: `${RNBackgroundDownloader.directories.documents}/file.zip`
}).begin((expectedBytes) => {
console.log(`Going to download ${expectedBytes} bytes!`);
}).progress((percent) => {
console.log(`Downloaded: ${percent * 100}%`);
}).done(() => {
console.log('Download is done!');
}).error((error) => {
console.log('Download canceled due to error: ', error);
});
// Pause the task
task.pause();
// Resume after pause
task.resume();
// Cancel the task
task.stop();
I am using the above code. In this i have problem that it downloads a file and save it as it. But i want to encode a file then save it in the internal directly of android folder. Let me know if anyone have a idea to do it. So that i can encode after that file will save.
Thanks
How about you download the file and then encode the local file and then save the encoded file and delete the original file.

Move file from tmp to documents using react-native-fs

I'm trying to move a file selected from a document picker to the Document Directory using react-native-fs and react-native-document picker.
However, I get the error below:
Error: “file name.mp3” couldn’t be moved to “Documents” because either the former doesn't exist, or the folder containing the latter doesn't exist.
What am I doing wrong?
FYI, I'm using iOS.
openDocumentPicker() {
DocumentPicker.show({
filetype: ['public.audio'],
},(error,url) => {
console.log(url);
this.saveAudio(url);
});
}
saveAudio(url) {
var destPath = RNFS.DocumentDirectoryPath + '/' + 'name';
RNFS.moveFile(url, destPath)
.then((success) => {
console.log('file moved!');
})
.catch((err) => {
console.log("Error: " + err.message);
});
}
I believe I've found the error. The issue was that the file I was uploading had a space in it. I needed to decode the URL first before uploading, like so:
var decodedURL = decodeURIComponent(url)
Then I could move the file over.
RNFS.copyFile(decodedURL, destPath)
It happened to me when destination folder doesn't exist.
[tid:com.facebook.react.JavaScript] 'error!', { [Error: The file “source.jpg” doesn’t exist.]
It's a wrong error message from react-native-fs. It should tell target path folder not exists.

React Native File system path for IOS

i am using a RNFetchBlob for getting files in react-native. Code is as follows -
RNFetchBlob.fs.readStream(
('/Users/UserName/Project/documents/' + this.state.name),
'base64',
4095)
.then((ifstream) => {
ifstream.open();
ifstream.onData((chunk) => {
this.setState({data: chunk});
})
ifstream.onError((err) => {
console.log('oops', err)
})
ifstream.onEnd(() => {
this._decodeData();
})
});
This code works perfectly when running it on an emulator on my macbook, but i was wondering what the file path would be running it on my iphone? Obviously - it cant find the file when i try to do so.
I would like some sort of non-absolute path to be used but not sure how this is done with RNFetchBlob. When loading images, require('../images/image.png') works perfectly, just not this scenario
Thanks in advance -