I'm writing an oscillator in JavaScript that creates a sweep(i.e. chirp) between sine wave frequencies. For testing, I'd like to write the samples(which are floats) to a wav file. How would I do this in Node.js? I've seen lots of information on the browser end of things but not anything specific to Node or anything that relies on browser APIs.
How can I write an array of audio samples to a wav file with Node.js?
2.5k Views Asked by Ten Bitcomb At
2
There are 2 best solutions below
4
GoodStuffing123
On
You can use the built in Node.js fs.writeFile() api to write to a file.
By the way I see it all you have to do is loop over your audio samples, add them to a string within the iteration, and put that string into a file like so:
const fs = require("fs");
// Code to generate audio
let audio = "";
samples.forEach((sample) => {
audio += sample;
});
fs.writeFile("path/to/file.wav or .mp3", audio, (err) => {
if (err) return console.error(err);
console.log("File successfully saved!");
});
If I'm understanding your question correctly, then this should work.
Related Questions in JAVASCRIPT
- Angular Show All When No Filter Is Supplied
- Why does a function show up as not defined
- I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
- Set "More" "Less" font size
- Using pagination on a table in AngularJS
- How to sort these using Javascript or Jquery Most effectively
- how to fill out the table with next values in array with one button
- State with different subviews
- Ajax jQuery firing multiple time display event for the same result
- Getting and passing MVC Model data to AngularJS controller
- Disable variable in eval
- javascript nested loops waiting for user input
- .hover() seems to overwrite .click()
- How to sort a multi-dimensional array by the second array in descending order?
- How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?
Related Questions in NODE.JS
- How to solve CERT_UNTRUSTED error in nodemailer
- Run a loop over a callback, node js
- Implementing prerender.io middleware in sails.js
- Token based authorization in nodejs/ExpressJs and Angular(Single Page Application)
- formatting path string in javascript
- One to One screensharing using WEBRTC
- Create polygon from grid (for collisions)
- Strange npm behavior when installing packages like grunt
- Convert JSON.gz to JSON in node js
- "Your npm version is outdated." but it's not. While install yo
- Why put methods on the prototype of a class instead of declaring them in the constructor?
- Node JS Async Response
- mongoose get property from nested schema after `group`
- Cannot Receive Incoming call on Twilio android Client
- How can I change a specific line in a file with node js?
Related Questions in AUDIO
- Play multiple audio files in a slider
- Unity3d AudioSource not creatable
- JavaFX can't play mp3 files
- iPhone simultaneous sound output
- Phonegap Build App - Play Audio
- HTML5 Audio pause not working
- Java boolean play button issue (play over and over again with each click)
- import a sound externally or from the library? AS3
- Set audio source
- Saving a sound bite as a ringtone
- Using OnAudioFilterRead with playOnAwake
- Audio recorded with Samsung does not play on iOS
- fftw of 16bit Audio :: peak appearing wrong at 2f
- How to Export an audio file with effect in iOS
- Tried multiple solutions onsite, none worked: Play <audio> on Konami code
Related Questions in WAV
- Release a wav file from being used by a process
- How to join mp3 and wav files
- Windows - sound recording program giving noise
- QSound::play("soundpath") call works but a QSound object doesn't
- How to save an audio capture in a wav file using ASIO and Naudio?
- Change WAV File In C
- Building OPENSMILE with portaudio in vs2012 fail
- Invalid format with getAudioInputStream, trying to play a sound in Java
- Loading and playing multiple .wav files in java
- Playing a wav file from a MemoryStream windows phone 8.1
- How to add echo effect to wav file in android?
- Export buffer to WAV in C++
- Reading WAV header renders wrong data
- Parsing a WAV/PCM audio
- WAV files at any rate except 44.1kHz have messed up sound
Related Questions in JAVASCRIPT-OSCILLATOR
- javascript oscillator volume not fully working
- Is it more expensive to create and close web audio oscillators or to keep running and manipulate the gain?
- How to get the real and imag arrays for createPeriodicWave for a piecewise periodic function?
- (Web Audio API) Oscillator node error: cannot call start more than once
- How does oscillator.detune() work in Web Audio API?
- WebAudio isn't giving any audio output
- JS Audio sequence of notes from Oscillator with Sleep function
- Is there a node.js module that can generate 1/f (pink noise) fluctuations?
- Web Audio API oscillator won't make any sound
- Javascript Audiocontext Oscillator Not Working on Windows Edge or Android Browsers
- Oscillator not stoppingor ramping down in Web Audio API
- Changing volume of oscillator in JavaScript?
- Using WebAudio to play a sequence of notes - how to stop asynchronously?
- How to connect/trigger elements in specific mouse-pressed combinations in p5.js
- How to beep on evey button click
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This can be done using the minimal package
node-wavand a snippet similar to the one below:First, install the dependency:
Then, use something like
Considering that you already know the application of your data, you know all the "constant" parameters (size of the output, bitrate, the actual data to be written, bitdepth).