Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: output buffer too small #79

Open
hxfdarling opened this issue Nov 3, 2017 · 0 comments
Open

Error: output buffer too small #79

hxfdarling opened this issue Nov 3, 2017 · 0 comments

Comments

@hxfdarling
Copy link

I want to transfrom wav to mp3 ,but i got an error Error: output buffer too small

let 	lame = require('lame')
const wav = require('wav')
const fs = require('fs')

function wav2mp3(input, output, next = function() {}) {
	const rs = fs.createReadStream(input)
	const ws = fs.createWriteStream(output)
	const reader = new wav.Reader()

	// the "format" event gets emitted at the end of the WAVE header
	reader.on('format', function(format) {
		const encoder = new lame.Encoder({
			// input
			channels: format.channels, // 2 channels (left and right)
			bitDepth: format.bitDepth, // 16-bit samples
			sampleRate: format.sampleRate, // 44,100 Hz sample rate

			// output
			bitRate: 128,
			outSampleRate: 22050,
			mode: lame.STEREO // STEREO (default), JOINTSTEREO, DUALCHANNEL or MONO
		})
		// the WAVE header is stripped from the output of the reader
		reader.pipe(encoder)
		encoder.pipe(ws)
	})
	// pipe the WAVE file to the Reader instance
	reader.on('finish', () => {
		rs.close()
		ws.close()
		next(null);
	})
	rs.pipe(reader)
}
wav2mp3('./xxx.wav', './xxx.mp3', (err) => {
	console.log('success')
})

files

xxx.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant