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
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in NODE.JS
- Using Puppeteer to scrape a public API only when the data changes
- How to request administrator rights?
- How do I link two models in mongoose?
- Variable inside a Variable, not updating
- Unable to Post Form Data to MongoDB because of picturepath
- Connection terminated unexpectedly while performing multi row insert using pg-promise
- Processing multiple forms in nodejs and postgresql
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How to change the Font Weight of a SelectValue component in React when a SelectItem is selected?
- My unban and ban commands arent showing when i put the slash
- how to make read only file/directory in Mac writable
- How can I outsource worker processes within a for loop?
- Get remote MKV file metadata using nodejs
- Adding google-profanity-words to web page
- Products aren't displayed after fetching data from mysql db (node.js & express)
Related Questions in AUDIO
- how to play a sounds in c# forms?
- Winsound not working isn't working at all
- Ringing noise overpowering voice / Recording audio with Max 9814 microphone on Raspberry pi pico using ADC Pin / Circuitpython
- How to take first x seconds of Audio from a wav file read from AWS S3 as binary stream using Python?
- gluon attach audio doesn't play any sound on android
- Implementing trim and fade filters with ffmpeg - MP3
- Unable to set device connection state as INPUT device type is none
- Is there a way to differentiate music and talking from a video?
- How to concatenate audio tracks and make them start a certain moment using Python?
- Combine two audio in different languages to one natural sounding
- STM32 - Serial Audio Interface (SAI) - dual data line transmit possible?
- playing mp3 downloaded via curllib gets cut short
- How to stream PCM audio to a speakers both on mac and linux in Node.js?
- Scikit-Maad -From the function rois.find_rois_cwt, I want to get a csv of the outputs so I can do my own analysis on it
- Using MediaPlayer slows down SoundPool sound effect
Related Questions in WAV
- Using MAX 9814 PCM data to create a .WAV file
- I'm getting chopping noises and incorrect results from my phase vocalizer in jupyter notebook
- How to implement pause/resume feature for wav audio with sounddevice in python
- WAV music extracts some features through librosa. How to restore this matrix to WAV format?
- Get PII durations (start-end time) from an Audio file using Transcription/other techniques
- Binary Visualisation of a WAV file using Python
- BINARY to WAV converted
- using gst-launch-1.0 to record audio to an audio file from any pipewiresrc input
- NAudio only plays sound on the default output device
- stm32 cubeIDE DMA DAC noise on DAC output
- Send OpenAI Text To Speech Wav stream to Twilio stream
- trying to record two channels from multi channel audio device into a wav file using the gstreamer c api without gst_parse_launch
- Write a numpy array to headerless wav file?
- Using webrtcvad to capture audio when the user starts speaking and stops speaking (like Siri) and then saving to a .wav file
- What kind of wav or wave sound data format is required in vosk nodejs library for speech recognition?
Related Questions in JAVASCRIPT-OSCILLATOR
- WebAudioAPI: Non-started oscillators still consume resources, stutter and crash - too many?
- How to beep on evey button click
- Oscillator not stoppingor ramping down in Web Audio API
- Javascript Audiocontext Oscillator Not Working on Windows Edge or Android Browsers
- Trying to detect when oscillator audio ends (javascript)
- How to get the real and imag arrays for createPeriodicWave for a piecewise periodic function?
- Is it more expensive to create and close web audio oscillators or to keep running and manipulate the gain?
- How to connect/trigger elements in specific mouse-pressed combinations in p5.js
- WebAudio isn't giving any audio output
- Oscillator built with react hooks won't stop
- audioContext oscillator gets 'stuck' after one second and doesn't stop
- Web Audio API oscillator won't make any sound
- Using WebAudio to play a sequence of notes - how to stop asynchronously?
- How does oscillator.detune() work in Web Audio API?
- Is there a node.js module that can generate 1/f (pink noise) fluctuations?
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 # Hahtags
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).